开发者

Obscure and encode a URL parameter

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.


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("my@email.com", STREAM_FILTER_WRITE));
var_dump(rot13("zl@rznvy.pbz", STREAM_FILTER_READ));

will give:

string(12) "zl@rznvy.pbz"
string(12) "my@email.com"


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜