Is there any way to hash a string, and un-hash it later?
For example, I want to hash an email address to make a unique link, and retrieve the email address when the link is visited.
It's more about obfuscation than hashing, as you can see.
You cannot hash and unhash a string but can use base64_encode and base64_decode to do a similar thing:
<?php
$str = 'This is an encoded string';
echo base64_encode($str);
?>
The above example will output:
VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==
You can decode it:
<?php
$str = 'VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==';
echo base64_decode($str);
?>
The above example will output:
This is an encoded string
As in the PHP.net manual:
There is no unhash. hash is a one way encryption. for that purpose you can save email and hash in a table and select email where hash equals to something.
id, email, hash
1 a@b.cc m3jf9s...
SELECT `email` from `activation_table` WHERE `hash` = 'm3jf9s...';
then display it on the page.