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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 19:48:28
Original
944 people have browsed it

今天在写程序的时候,发现后台没法解析前台的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)
Copy after login

如此这般,英文均没有问题,如果是中文,就会出现%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;
}
Copy after login

这样一来,

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



Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template