Skip to content

Instantly share code, notes, and snippets.

@dhaupin
dhaupin / dev_script_filter_os_url.php
Last active March 4, 2016 16:29
Function - User input string to EN sanitized filename, directory, slug, identifier, etc
<?php
// @last https://3v4l.org/iSgi8
// @same http://stackoverflow.com/a/34908708/2418655
// Start sample
$raw_str = '.....&lt;div&gt;&lt;/div&gt;<script></script>&amp; Weiß Göbel 中文百强网File name %20 %20 %21 %2C Décor \/. /. . z \... y \...... x ./ “This name” is & 462^^ not &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = that grrrreat -][09]()1234747) საბეჭდი-და-ტიპოგრაფიული';
$fallback_str = 'generated__' . date('Y-m-d_H-m_A');
$bad_extension = '....t&+++a()r.gz[]';
@dhaupin
dhaupin / dev_script_filter_char_print.php
Last active March 4, 2016 16:30
Function - Filter PDF/print rogue special characters from WYSIWYG "full-paste" or rando DB source
<?php
// @last https://3v4l.org/0LHkO
// Start sample
$str = '® ‡ ¼';
echo clean($str, false, false);
// End sample
@dhaupin
dhaupin / dev_schema_ld_organization.js
Created February 12, 2016 15:24
JSON-LD - Schema.org organization markup
<script type="application/ld+json">{
"@context":"http://schema.org",
"@type":"HomeGoodsStore",
"name":"Our Store",
"legalName":"Our Company",
"url":"https://www.ourstore.com/",
"sameAs":"http://plus.google.com/99999999999999",
"logo":"https://www.ourstore.com/image/logo.png",
"photo":"https://www.ourstore.com/image/ourstore.png",
"description":"People give us money and we give them GLORIOUS PRODUCTS.",
@dhaupin
dhaupin / dev_script_routing_proxy_ssl.php
Last active June 23, 2020 16:21
Function - Route reverse proxy SSL flags, rewrite REMOTE_ADDR, and add PROTOCOL index
<?php
// Rewrite client IP based on proxy headers
$ip_pool = array(
!empty($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : '',
!empty($_SERVER['HTTP_CF_PSEUDO_IPV4']) ? $_SERVER['HTTP_CF_PSEUDO_IPV4'] : '',
!empty($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '',
!empty($_SERVER['HTTP_X_FORWARDED']) ? $_SERVER['HTTP_X_FORWARDED'] : '',
!empty($_SERVER['HTTP_FORWARDED_FOR']) ? $_SERVER['HTTP_FORWARDED_FOR'] : '',
@dhaupin
dhaupin / dev_script_asset_cachebuster.php
Last active November 10, 2016 19:51
Function - Cachebuster - Add timestamp to assets in order to break out of browser caching
<?php
if (!function_exists('addTimestamp')) {
function addTimestamp($src, $remote = false, $man_v = '') {
if (empty($src)) {
return;
} elseif ($_SERVER['HTTP_HOST'] === $_SERVER['SERVER_NAME']) {
$local_root = $_SERVER['DOCUMENT_ROOT'] . '/';
preg_match('/^([https]+:)?\/\//', $src, $src_proto);
@dhaupin
dhaupin / dev_script_logger_console_sys.php
Last active March 4, 2016 16:31
Function - Send debug logs to browser console and/or system log (var/log/messages)
<?php
// This goes in your log class, for this example we will access it in the view as $this->log->consoled
// These call a native platform log method, for this example we will call it $this->write()
public function syslog($message, $errlog = false) {
syslog(LOG_NOTICE, 'debug: (' . $_SERVER['SERVER_NAME'] . '@' . $_SERVER['SERVER_ADDR'] . ') [INFO] ' . $this->clean($message));
if ($errlog) {
$this->write('@System | ' . $message);
@dhaupin
dhaupin / dev_script_bot_tarpit.php
Last active December 12, 2022 03:19
Function - Bot honeypot + timewaster tarpit + Fail2Ban
<?php
// Dribbler Tarbaby Community v.0.1.0 - Copyright 2013-2014 under GNU/GPL
// Original script by Mike (zaphod@spambotsecurity.com)
// http://www.stopforumspam.com/forum/viewtopic.php?pid=41173
//
// Contributors:
// John Darkhorse
// Derek Haupin (dhaupin@gmail.com)
//
// @@ WARNING @@
@dhaupin
dhaupin / dev_script_google_merch_taxonomy.php
Last active September 12, 2021 09:26
Function - Parse Google merchant center shopping categories into Array or JSON - works with search url param or direct category_id argument
<?php
// This is part of a product class, this function shalt also be available via route with optional ?search= param
// $this->request->get is platform specific, change it to whatever your request wrapper uses
public function googlecats($cat_ids = false) {
// default format
$json = true;
@dhaupin
dhaupin / dev_script_x_debugger_logger.php
Last active April 28, 2017 17:09
Function - print_r() and trace using x_r() wrapper with optional JS console.dir() or clean exit(). Additional x_dump() simple file dump.
<?php
// Exits with a print_r and call trace for debugging
// $hidden inits array output into browser console
// Backtrace: jurchiks101 at gmail dot com - http://php.net/manual/en/function.debug-backtrace.php#112238
if (!function_exists('x_r')) {
function x_r($obj, $exit = true, $return = true, $hidden = false, $console_msg = '') {
// include a debug call trace
$e = new Exception();
@dhaupin
dhaupin / dev_script_chk_common_passwords.php
Last active March 11, 2016 01:10
Function - Parse list of 10,000 most used passwords and return JSON or Object match for use on account validation
<?php
// This is part of a form class, this function shalt also be available via route with optional ?search= param
// password list: https://github.com/danielmiessler/SecLists/blob/master/Passwords/10_million_password_list_top_10000.txt
// example: www.example.com/chkpw.php&search=dra would return "dragon" (always returns the first pass found)
public function chkpass($password = false, $json = true) {
$pool = $output = array();
$pool = file('https://src.creadev.org/apps/pwlist/pwlist.txt', FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);