Skip to content

Instantly share code, notes, and snippets.

Working from home

corbpie cp6

Working from home
View GitHub Profile
cp6 / rdt_comments.php
Created Apr 5, 2021
PHP Reddit API get post comments
View rdt_comments.php
function commentData(array $data): array
if (isset($data['data']['body'])) {
$d = $data['data'];
if (isset($d['author_flair_richtext'][0])) {
$frt = $d['author_flair_richtext'];
if ($frt[0]['e'] === 'text') {
$flair = $frt[0]['t'];
cp6 / pdo_insert_loop.php
Last active Apr 5, 2021
PHP PDO insert from a loop
View pdo_insert_loop.php
$db = new PDO("mysql:host=;dbname=test;charset=utf8mb4", 'root', '');
$insert = $db->prepare("INSERT IGNORE INTO `objects` (`id`, `color`) VALUES (?, ?);");
$test_array = ['Red', 'Orange', 'Pink', 'Lime', 'Yellow', 'Gold', 'Green', 'Blue', 'Purple', 'Maroon', 'Silver', 'Aqua'];
$id = 0;
foreach ($test_array as $c) {
cp6 / pdo_mysql_backup.php
Last active Mar 28, 2021
PHP PDO MySQL backup script with compression
View pdo_mysql_backup.php
$backup_config = array(
'DB_HOST' => '',////Database hostname
'DB_NAME' => 'test_db',//Database name to backup
'DB_USERNAME' => 'root',//Database account username
'DB_PASSWORD' => '',//Database account password
'SAVE_DIR' => '',//Folder to save file in
'SAVE_AS' => 'test_db-',//Prepend filename
'APPEND_DATE_FORMAT' => 'Y-m-d-H-i',//Append date to file name
cp6 / bar_chart.php
Last active Apr 12, 2021
PHP MySQL single chart.js bar chart
View bar_chart.php
//Config options for chart data
$player_id = 202331;//Paul George player id
$season_type = 2;//2 is regular season, 3 is playoffs
//Design / Display options:
$bootstrap_css_url = '';
$chartjs_js_url = '';
$background_color = '#7bbbbb';//Page background color
cp6 /
Created Feb 16, 2021
PHP PDO MySQL Cheat sheet guide

PHP PDO MySQL Cheat sheet guide

A guide on the basics for using PDO PHP for MySQL with pre-prepared statements.

Table of Contents

  1. Creating connection

    1a inline

cp6 / api.php
Created Feb 7, 2021
Authenticating and protecting Ajax requests with PHP
View api.php
if (session_status() == PHP_SESSION_NONE) {
session_start();//Start session if none exists/already started
if (isset($_POST['ajax_call']) || isset($_GET['ajax_call'])) {
$headers = getallheaders();
if (isset($headers['token'])) {
$header_token = $headers['token'];
if ($header_token != $_SESSION['token']) {
cp6 / content.html
Last active Jan 5, 2021
Simple Bootstrap WordPress blog template files
View content.html
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-10 mx-auto">
<div class="post-heading">
<h1>Man must explore, and this is exploration at its greatest</h1>
<h2 class="subheading">Problems look mighty small from 150 miles up</h2>
<span class="meta">Posted by
<a href="#">Boss</a>
on January 5, 2021</span>
cp6 / index.html
Last active Jan 4, 2021
Simple Bootstrap WordPress blog template files
View index.html
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
cp6 / get_params.php
Created Oct 17, 2020
PHP build URL from GET paramaters
View get_params.php
$params = $_GET;
$count = 0;
foreach ($params as $key => $value) {
if ($count === 0) {
echo "?{$key}={$value}";
} else {
echo "&{$key}={$value}";
//echo "$key : $value<br>";
cp6 / form.html
Created Oct 7, 2020
HTML form inputs based on a select element
View form.html
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-header"><h2 class="text-center">Input based on select</h2></div>
<div class="card-body"><p class="lead text-center">Example of a select form with an input appearing
based on the selection.</p>
<p class="text-center">Change the select input below to see the changes</p>
<form id="submit-form" method="post" action="" role="form">
<div class="row">