Skip to content

Instantly share code, notes, and snippets.

View daveh's full-sized avatar

Dave Hollingworth daveh

View GitHub Profile
@daveh
daveh / .htaccess
Last active January 12, 2025 19:36
Routes, Routers and Routing in PHP (code to accompany https://youtu.be/JycBuHA-glg)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
@daveh
daveh / composer.json
Last active December 13, 2024 06:02
Loading Classes Automatically in PHP (code to accompany https://youtu.be/93pCiZT99Ks)
{
"autoload": {
"psr-4": {
"": "src/"
}
}
}
@daveh
daveh / index.php
Last active December 28, 2024 16:04
Create a Google Login Page in PHP (code to accompany https://youtu.be/yi2b9U1kQyc)
<?php
require __DIR__ . "/vendor/autoload.php";
$client = new Google\Client;
$client->setClientId("your client ID here");
$client->setClientSecret("your client secret here");
$client->setRedirectUri("http://localhost/redirect.php");
@daveh
daveh / index.php
Last active July 31, 2024 17:42
File Uploads in a REST API in PHP (source to accompany https://youtu.be/0C1s7E6-1mw)
<?php
declare(strict_types=1);
use Slim\Factory\AppFactory;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
require dirname(__DIR__) . "/vendor/autoload.php";
@daveh
daveh / openssl.php
Last active April 10, 2024 13:58
Encrypt and Decrypt Data Securely in PHP: OpenSSL, Sodium & defuse/php-encryption (code to accompany https://youtu.be/VCdFFQvJl2k)
<?php
$cipher_algo = 'AES-256-CBC';
$key = 'encryption key here';
$iv_length = openssl_cipher_iv_length($cipher_algo);
$iv = openssl_random_pseudo_bytes($iv_length);
@daveh
daveh / Container.php
Last active January 17, 2025 00:09
Dependency Injection in PHP (code to accompany https://youtu.be/TqMXzEK0nsA)
<?php
class Container
{
private array $registry = [];
public function set(string $name, Closure $value): void
{
$this->registry[$name] = $value;
}
@daveh
daveh / books.json
Last active February 19, 2024 21:43
Parse JSON in PHP | How to validate and process nested JSON data (code to accompany https://youtu.be/KZW2jtUhKZA)
[
{
"title": "Fairy Tales",
"pages": 100,
"price": 3.99,
"available": true,
"language": null,
"categories": ["children", "fiction"],
"author": {
"firstname": "Hans Christian",
@daveh
daveh / composer.json
Last active June 10, 2024 14:46
Send an email with an attachment using an API in PHP (code to accompany https://youtu.be/6ncbK1aBl1w)
{
"require": {
"wildbit/postmark-php": "^5.0"
}
}
@daveh
daveh / form.php
Last active February 13, 2025 11:23
Send SMS Messages with PHP (code to accompany https://youtu.be/obolAwbx388)
<!DOCTYPE html>
<html>
<head>
<title>PHP SMS</title>
<meta charset="UTF-8" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css" />
</head>
<body>
<h1>PHP SMS</h1>
@daveh
daveh / checkout.php
Last active April 13, 2025 08:35
Simple PHP Stripe Checkout (code to accompany https://youtu.be/1KxD8J8CAFg)
<?php
require __DIR__ . "/vendor/autoload.php";
$stripe_secret_key = "your Stripe secret key here";
\Stripe\Stripe::setApiKey($stripe_secret_key);
$checkout_session = \Stripe\Checkout\Session::create([
"mode" => "payment",