Obscure and encode a URL parameter

5.5k Views Asked by At

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.

2

There are 2 best solutions below

2
On BEST ANSWER

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]"
0
On

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