Skip to content

Instantly share code, notes, and snippets.

@rchrd2
rchrd2 / test-php-basic-auth.php
Last active February 1, 2024 21:18 — forked from westonruter/test-php-basic-auth.php
PHP basic auth example
<?php
function require_auth() {
$AUTH_USER = 'admin';
$AUTH_PASS = 'admin';
header('Cache-Control: no-cache, must-revalidate, max-age=0');
$has_supplied_credentials = !(empty($_SERVER['PHP_AUTH_USER']) && empty($_SERVER['PHP_AUTH_PW']));
$is_not_authenticated = (
!$has_supplied_credentials ||
$_SERVER['PHP_AUTH_USER'] != $AUTH_USER ||
$_SERVER['PHP_AUTH_PW'] != $AUTH_PASS
@zaus
zaus / FormRepo.js
Last active January 13, 2023 01:38
Preserve form values across page loads -- i.e. persistent forms. Uses `localStorage` to persist, `jQuery` for utilities.
var FormRepo = function (namespace) {
/// <summary>Persistent form values, saves to localStorage</summary>
/// <param name="namespace" type="String">the namespace to store values in localStorage</param>
// should also protect per page, since we could have the same forms in various places
this.N = namespace + '.' + window.location.pathname;
};
$.extend(FormRepo.prototype, {
namespace: function (key) {
return this.N + '.' + key;