I highly recommend Create a secure encrypted string by Joe Riggs .
The attached code is procedural, but very simple to convert to OO. I used it to do what you do, in which some information (usually a hash of the email and user ID) is encrypted / encrypted so that the user clicks to activate their account.
The functions you want to view are url_base64_decode and url_base64_encode , in which certain characters are rewritten to be URL safe (for example, removing / and replacing it with ~ ).
[edit]
Here is the code of my class based on the code above: http://codepad.org/lzevA4k1
Using:
$cryptUtil = new RPK_Crypt(); $string = 'Unencrypted string'; $eString = $cryptUtil->encrypt($string); $dString = $cryptUtil->decrypt($eString); var_dump($dString == $string);
source share