Skip to content

Instantly share code, notes, and snippets.

View daveh's full-sized avatar

Dave Hollingworth daveh

View GitHub Profile
@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 April 28, 2024 15:51
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 March 3, 2024 00:34
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 28, 2024 14:58
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 24, 2024 09:33
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",
@daveh
daveh / .env.example
Last active December 2, 2023 16:54
Configuring PHP Applications (code to accompany https://youtu.be/L5E2HSHrDjw)
DATABASE_HOSTNAME=localhost
DATABASE_USERNAME=db_username
DATABASE_PASSWORD=db_password
DATABASE_NAME=db_name
@daveh
daveh / form.php
Last active April 1, 2024 13:46
Generate QR Codes with PHP (code to accompany https://youtu.be/8xPWPGxL7Xk)
<!DOCTYPE html>
<html>
<head>
<title>Generating QR Codes with PHP</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">
</head>
<body>
<h1>Generating QR Codes with PHP</h1>
@daveh
daveh / form.html
Last active December 18, 2023 04:21
PHP File Uploads (code to accompany https://youtu.be/K_W5ZqwEcqs)
<!DOCTYPE html>
<html>
<head>
<title>PHP File Uploads</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">
</head>
<body>
<h1>PHP File Uploads</h1>
@daveh
daveh / index.html
Created September 7, 2022 16:22
Prevent favicon requests: the fastest way to stop the browser from requesting favicon.ico (code to accompany https://youtube.com/shorts/UI_yJY5jMrQ)
<link rel="icon" href="data:,">