0

我只想在参数中获取 URL 字符串。所以我在下面编码:

//In my HTML file.
<script>
document.write('<iframe id="ifr1" 
src="http://{domain}/prj.php?url=https://www.google.co.kr/search?sugexp=chrome,mod=3&sourceid=chrome&ie=UTF-8&q=url+utf8+encoding#sclient=psy-ab&hl=ko&newwindow=1&prmdo=1&tbm=klg&q=google&oq=google&aq=f&aqi=g10&aql=&gs_l=serp.3..0l10.2207859.2208404.3.2208459.6.4.0.1.1.3.496.1353.2-2j1j1.4.0...0.0.O1lbexylHQM&pbx=1&prmdo=1&bav=on.2,or.r_gc.r_pw.,cf.osb&fp=b8fee9fdb4e7f90&biw=1440&bih=828&a=' +'asdf'+" width="100%" height="100%" frameborder="0">   </iframe>');
</script>

//In my php file
$message = $_GET['url'];
echo("$message");

但我只得到'https://www.google.co.kr/search?sugexp=chrome,mod=3'。

怎么了?

我想获取整个 URL 字符串。包括 &,?, 或其他所有内容。

4

2 回答 2

1

您需要使用encodeURIComponent对 url 参数进行编码。

于 2012-06-09T04:17:53.217 回答
0

原因是您将一种编码转换为另一种编码。

第一个是:

prj.php?url=[somedata]

其中 [somedata] 是带有另一个键/值集合的 URL:

https://url/etc/search?key1=value1&key2=value2

如果 url 参数没有进行urlencoded,则无法区分参数 of/prj.php和参数/search,假设所有用语法定义的参数&key=value&key=value...都属于第一页。

诀窍是对url 参数进行url 编码,但如何执行取决于上下文。

如果 url 是通过 PHP 动态生成的,请使用该urlencode()函数。

如果您的 url 是硬编码的(不是通过 PHP 生成的),您可以为自己编写一个小的 PHP 工具来完成这项工作,或者使用像http://www.opinionatedgeek.com/dotnet/tools/urlencode/这样的在线编码器编码.aspx

于 2012-06-09T06:29:26.090 回答