Home >php教程 >php手册 >用PHP解析JS escape加密过的数据!

用PHP解析JS escape加密过的数据!

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 19:48:28942browse

今天在写程序的时候,发现后台没法解析前台的ajax数据。经过DEBUG,发现ajax发送前夕,数据被使用javascript的escape处理过了。 url = url + n= + vname + v= + escape(val) 如此这般,英文均没有问题,如果是中文,就会出现%uXXXX之类的东西。后面php怎么解

今天在写程序的时候,发现后台没法解析前台的ajax数据。经过DEBUG,发现ajax发送前夕,数据被使用javascript的escape处理过了。

url = url + "&n=" + vname + "&v=" + escape(val)

如此这般,英文均没有问题,如果是中文,就会出现%uXXXX之类的东西。后面php怎么解析呢?加个函数吧:

function js_unescape($str)
{
	$ret = '';
	$len = strlen($str);
	for ($i = 0; $i >6)).chr(0x80|($val&0x3f));
			else $ret .= chr(0xe0|($val>>12)).chr(0x80|(($val>>6)&0x3f)).chr(0x80|($val&0x3f));
			$i += 5;
		} else if ($str[$i] == '%') {
			$ret .= urldecode(substr($str, $i, 3));
			$i += 2;
		} else $ret .= $str[$i];
	}
	return $ret;
}

这样一来,

js_unescape($_GET('v'))就是解析的数据了



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn