我们在开发过程中,有的时候GET传值,字符串太长,我们可以用这个方法,在传值之前先调用函数lock_url(加密字符串),加密以后在传递,GET接受以后用函数unlock_url(待解密字符串)进行解密。

如果大家有更好更简单的方法,发评论区我们一起讨论学习!

function lock_url($txt)

{

$key = ]!L]<_w{O}zEIs!.f(T[|ZGQaxS":?#`v%EburotLZi"KdKs@QivlJ[PjWw`.wcT; //key

$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=+";

$nh = rand(0,64);

$ch = $chars[$nh];

$mdKey = md5($key.$ch);

$mdKey = substr($mdKey,$nh%8, $nh%8+7);

$txt = base64_encode($txt);

$tmp = ;

$i=0;$j=0;$k = 0;

for ($i=0; $i<strlen($txt); $i++) {

$k = $k == strlen($mdKey) ? 0 : $k;

$j = ($nh+strpos($chars,$txt[$i])+ord($mdKey[$k++]))%64;

$tmp .= $chars[$j];

}

return urlencode($ch.$tmp);

}

//解密函数

function unlock_url($txt)

{

$key = ]!L]<_w{O}zEIs!.f(T[|ZGQaxS":?#`v%EburotLZi"KdKs@QivlJ[PjWw`.wcT;//key

$txt = urldecode($txt);

$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=+";

$ch = $txt[0];

$nh = strpos($chars,$ch);

$mdKey = md5($key.$ch);

$mdKey = substr($mdKey,$nh%8, $nh%8+7);

$txt = substr($txt,1);

$tmp = ;

$i=0;$j=0; $k = 0;

for ($i=0; $i<strlen($txt); $i++) {

$k = $k == strlen($mdKey) ? 0 : $k;

$j = strpos($chars,$txt[$i])-$nh - ord($mdKey[$k++]);

while ($j<0) $j+=64;

$tmp .= $chars[$j];

}

return base64_decode($tmp);

}

分类: 软件分享 标签: 暂无标签

评论

暂无评论数据

暂无评论数据

目录