Created
April 10, 2017 19:52
-
-
Save tomfordweb/bcb36baaa6db538b28d2f9a155debe0f to your computer and use it in GitHub Desktop.
URL Safe Hash Methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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, '-_,', '+/=')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mainly used for unsubscribe links in marketing emails, but could be used for a bunch of crap.