Skip to content

Instantly share code, notes, and snippets.

View daveh's full-sized avatar

Dave Hollingworth daveh

View GitHub Profile
@daveh
daveh / index.php
Last active September 11, 2024 14:46
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 September 7, 2024 05:37
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 August 28, 2024 06:03
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 September 15, 2024 08:19
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 August 30, 2024 07: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>