I want to encrypt a URL variable so that the user can't see the information when it is passed. I've found several scripts online but none of them work. Most seem to lean toward using base-64. Could someone help me write a short script that would encode or encrypt and then reverse that in the next page? It doesn't have to be super secure, just enough to mask an email address to the average user.
A:
You can use a symmetric encryption algorithm. You can use mcrypt_encrypt and mcrypt_decrypt functions in mcrypt library.
http://php.net/manual/en/function.mcrypt-encrypt.php http://www.php.net/manual/en/function.mcrypt-decrypt.php
Zafer
2010-08-26 23:10:16
A:
Rufinus
2010-08-26 23:15:07
A:
If you're not concerned about security, you can just use rot13:
function rot13($string, $mode) {
$s = fopen("php://memory", "rwb");
stream_filter_append($s, "string.rot13", STREAM_FILTER_WRITE);
fwrite($s, $string);
rewind($s);
return stream_get_contents($s);
}
var_dump(rot13("[email protected]", STREAM_FILTER_WRITE));
var_dump(rot13("[email protected]", STREAM_FILTER_READ));
will give:
string(12) "[email protected]" string(12) "[email protected]"
Artefacto
2010-08-26 23:30:50
Thanks, Artefacto. How do I get it to return just the email without the string information or the quotes?
2010-08-26 23:50:45
@shu The return value of `rot13` doesn't have any string information or quotes. Those are added by `var_dump`.
Artefacto
2010-08-26 23:51:56