Skip to content

Instantly share code, notes, and snippets.

View AdamZWinter's full-sized avatar

Adam Winter AdamZWinter

  • Seattle, WA, USA
View GitHub Profile
@AdamZWinter
AdamZWinter / PHP_POST.gist
Created March 8, 2020 03:41
POST with PHP file_get_contents to Google API
$grant_type = 'refresh_token';
$url = 'https://oauth2.googleapis.com/token';
$data = array('refresh_token' => $refresh_token, 'client_id' => $client_id, 'client_secret' => $client_secret, 'redirect_uri' => $redirect_uri, 'grant_type' => $grant_type, 'scope' => $scope );
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
:root {
--myPurple: 8, 0, 24;
--purpleButton: 25, 0, 75;
--offWhite: 195, 210, 190, 1;
--backGrey: 40, 40, 40;
--linkBlue: 195, 210, 255, 1;
}
/* a is between zero and one. */
@AdamZWinter
AdamZWinter / header.gist
Last active April 1, 2020 20:57
Secure site header
<?php
//header.php
if(!isset($_SESSION))
{
ini_set('session.cookie_lifetime', 0);
ini_set('session.use_cookies', 1);
ini_set('session.use_only_cookies', 1);
ini_set('session.use_strict_mode', 1);
ini_set('session.cookie_httponly', 1);
ini_set('session.cookie_secure', 1);
function openWindowWithPostRequest() {
var winName='MyWindow';
var winURL='search.action';
var windowoption='resizable=yes,height=600,width=800,location=0,menubar=0,scrollbars=1';
var params = { 'param1' : '1','param2' :'2'};
var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", winURL);
form.setAttribute("target",winName);
for (var i in params) {
// buffer all upcoming output
ob_start();
echo 'All done. Goodbye.';
// get the size of the output
$size = ob_get_length();
// send headers to tell the browser to close the connection
header("Content-Length: $size");
header('Connection: close');
<div id="formInputs">
<p>
<input type="text" name="email" id="email" style="width:67%;" placeholder="Email*"/>
<input type="password" name="password" id="password" style="width:67%;" placeholder="Password*"/>
</p>
<button id="reviewButton" onclick="login()" class="buttonLogin">Log In</button>
</div>
<div id="for-logged-in-user-only" style="display:none;"></div>
@AdamZWinter
AdamZWinter / PHP MySQL database table to HTML table
Created June 5, 2020 18:28
Common steps for displaying database table.
<?php
require('/var/www/html/.../header.php');
$active = 'yes';
$query = "SELECT * FROM calendars WHERE active = ?";
$stmt = $db->prepare($query);
$stmt->bind_param('s', $active);
$stmt->execute();
$result = $stmt->get_result();
@AdamZWinter
AdamZWinter / PHP_eval.gist
Created June 6, 2020 06:34
Evaluating math expressions written as strings
echo '<p>';
function evaluate_everything($values, $expressions) {
$output = [];
foreach($expressions as $expression) {
$row = [];
foreach($values as $value){
$str = '';
eval("\$str = \"$expression\";");
<?php
echo '
<table width=50%>
<thead>
<tr>
<th width=60%><p>Name</p></th>
<th width=20%><p>Owner</p></th>
<th width=20%><p>Permission</p></th>
</tr>