本文实例讲述了PHP实现URL加密解密的方法。分享给大家供大家参考,具体如下:
PHP;">
无标题文档
PHP
function query_encode($sQuery)
{//加密链接
if(strlen($sQuery)==0)
{
return '';
}
else
{
$s_tem = preg_replace("/&/i",'&',$sQuery);
$s_tem = preg_replace("/&/i",$s_tem);
$a_tem = explode('&',$s_tem);
shuffle($a_tem);
$s_tem = implode('&',$a_tem);
$s_tem = rawurlencode($s_tem);
$s_tem = base64_encode($s_tem);
$s_tem = strrev($s_tem);
return $s_tem;
}
}
function query_decode($sEncode)
{//解密链接
if(strlen($sEncode)==0)
{
return '';
}
else
{
$s_tem = strrev($sEncode);
$s_tem = base64_decode($s_tem);
$s_tem = rawurldecode($s_tem);
return $s_tem;
}
}
function rebuild_GET()
{//重写$_GET全局变量
$_GET = array();
$s_query = $_SERVER['QUERY_STRING'];
if(strlen($s_query)==0)
{
return;
}
else
{
$s_tem = query_decode($s_query);
$a_tem = explode('&',$s_tem);
foreach($a_tem as $val)
{
$tem = explode('=',$val);
$_GET[$tem[0]] = $tem[1];
}
}
}
rebuild_GET();
echo 'GET:
for($i=1; $i<10; $i++) { $s_url = query_encode('ac=index:logo& style="color: #007700">.$i); echo sprintf('
',$s_url,$s_url); } ?>
'.print_r($_GET,true).''; function testGET() { echo 'Function GET:
'.print_r($_GET,true).''; } testGET(); ?>
for($i=1; $i<10; $i++) { $s_url = query_encode('ac=index:logo& style="color: #007700">.$i); echo sprintf('
',$s_url,$s_url); } ?>