分享

求PHP高手:php 解密JS中的escape的代码

 玉屏风散很好喝 2015-03-23
希望给个详细解释,最好附上每段代码的用法说明!希望不要再网上找的,我找了很多,都不好使,也许是我不懂网上的代码罢了,如果你觉得网上的代码可行,最好给我详细解释一下用法 ,以及怎么赋予变量等等...无限感激,好用的话,加50分!
-----------------------------------------------------------------------------------------------
说下我的代码:
如下是JS代码:
<script type="text/javascript">document.write("<a href=rd.php?class=" + escape('行业分析') + ">行业分析</a>");</script>
对“行业分析”这几个字加密成功了的!
如下是PHP获取参数:要求解密,解密后从数据库提出数据
<?
...
$class=$_GET["class"];
请求解密(传过来的加密字符串)......HELP!
$sql="select * from $demo where class = '$class' order by id desc";
$res=mysql_query($sql) or die("出错了:".mysql_error());
?>




本例经过我测试没有问题.
<?
function utf8RawUrlDecode ($source) {
$decodedStr = "";
$pos = 0;
$len = strlen ($source);
while ($pos < $len) {
$charAt = substr ($source, $pos, 1);
if ($charAt == '%') {
$pos++;
$charAt = substr ($source, $pos, 1);
if ($charAt == 'u') {
// we got a unicode character
$pos++;
$unicodeHexVal = substr ($source, $pos, 4);
$unicode = hexdec ($unicodeHexVal);
$entity = "&#". $unicode . ';';
$decodedStr .= utf8_encode ($entity);
$pos += 4;
}
else {
// we have an escaped ascii character
$hexVal = substr ($source, $pos, 2);
$decodedStr .= chr (hexdec ($hexVal));
$pos += 2;
}
} else {
$decodedStr .= $charAt;
$pos++;
}
}
return $decodedStr;
}
$test = '%u884C%u4E1A%u5206%u6790';//js escape过的'行业分析';
echo utf8RawUrlDecode($test);
?>


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多