Skip to content

Instantly share code, notes, and snippets.

@tomfordweb
Created April 10, 2017 19:52
Show Gist options
  • Save tomfordweb/bcb36baaa6db538b28d2f9a155debe0f to your computer and use it in GitHub Desktop.
Save tomfordweb/bcb36baaa6db538b28d2f9a155debe0f to your computer and use it in GitHub Desktop.
URL Safe Hash Methods
<?php
/**
* Generate a hashed string that is URL save
* @param string $string The string to hash
* @return string Hashed string
*/
function urlSafeHashMake($string)
{
return strtr(base64_encode($string), '+/=', '-_,');
}
/**
* Decode a URL safe hash string
* @param string $string The string to decipher
* @return string The deciphered string
*/
function urlSafeHashDecode($string)
{
return base64_decode(strtr($string, '-_,', '+/='));
}
}
@tomfordweb
Copy link
Author

Mainly used for unsubscribe links in marketing emails, but could be used for a bunch of crap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment