Skip to content

Instantly share code, notes, and snippets.

@bradleyhodges
bradleyhodges / detectbrowser.php
Created June 11, 2018 06:42
Detect Chrome and Firefox
<?php
// Please note that User Agents can be *EASILY* spoofed. Don't use this as a
// reliable indicator for security purposes. ie. don't trust anything the user
// tells you - that includes user agents and IP addresses.
function detectBrowser($useragent) {
$detectedBrowser = explode(" ", $useragent, 20);
$temp["dtbr_counter"] = true; foreach ($detectedBrowser as &$value) {
if ($temp["dtbr_counter"]) {
$temp["dtbr_exploded"] = explode("/", $value);

Keybase proof

I hereby claim:

  • I am bradleyhodges on github.
  • I am bradleyhodges (https://keybase.io/bradleyhodges) on keybase.
  • I have a public key whose fingerprint is 79D0 52C2 B13B 26CC B71C C4F5 B392 94E6 80D3 EC0F

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am bradleyhodges on github.
  • I am bradleyhodges (https://keybase.io/bradleyhodges) on keybase.
  • I have a public key whose fingerprint is C109 AAA7 2D0E 046E E7C3 7160 A0D7 6880 E2CC E0A9

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am cheapapples12 on github.
  • I am bradleyhodges (https://keybase.io/bradleyhodges) on keybase.
  • I have a public key ASBwpng0PVz9exBUDCsA0BzXPf1m-ybFrHVNvZboCUDnuQo

To claim this, I am signing this object:

/* smoothscroll.js by @CheapApples12. Software provided without warranty. ©Copyright @CheapApples12 2017. All rights reserved.
/ Do not remove this attribution statement.
/ Use html "data-offset" attribute to offset scroll for headers and navbars. Eg. <a href="#test" data-offset="60" />
*/
$(function() {
$('a[href*="#"]:not([href="#"])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
<?php
class SaferCrypto extends UnsafeCrypto {
const HASH_ALGO = 'sha256';
public static function encrypt($message, $key, $encode = false) {
list($encKey, $authKey) = self::splitKeys($key);
$ciphertext = parent::encrypt($message, $encKey);
$mac = hash_hmac(self::HASH_ALGO, $ciphertext, $authKey, true);
if ($encode) {
@bradleyhodges
bradleyhodges / protectemail.php
Created May 2, 2017 08:30
PHP Email Protector
function protectEmail($email) {
$suffix = substr($email, strpos($email, "@") + 1);
$email = str_replace($suffix, "", $email);
$email = str_replace("@", "", $email);
if (strlen($email) > 3) {
$f3c = mb_substr($email, 0, 3);
$rlength = (strlen($email) - 3);
$email = $f3c . str_repeat("*", $rlength);
return $email . "@" . $suffix;
} else {