php 重定向和查询字符串
我有脚本,
<?php
$to = $_GET["to"];
header("Location: $to");
?>
如果我调用参数 $ 中的脚本
out.php?to=http://site.ru/page.php?param1=1¶m2=2
只是 http://site.ru/page.php?param1=1&
如何修复?我想要 $to = http://site.ru/page.php?param1=1¶m2=2
i have script
<?php
$to = $_GET["to"];
header("Location: $to");
?>
if i call script such
out.php?to=http://site.ru/page.php?param1=1¶m2=2
in param $to be only http://site.ru/page.php?param1=1&
how to fix? i want that $to = http://site.ru/page.php?param1=1¶m2=2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您可以在调用
out.php
的站点上转义 URL:You can escape the URL at the site calling
out.php
:&
是 URI 中的保留字符。当您访问此 URL 时,¶m2=2
被解释为属于当前 URL,不属于to
的值。如果你想按字面意思传输它,你必须用
% 编码它26
:大多数编程语言都提供了这样做的函数。 (例如 JavaScript,PHP)。最好的办法是对整个 URL 进行编码。
&
is a reserved character in an URI. When you access this URL,¶m2=2
is interpreted as belonging to the current URL and not to the value ofto
.If you want to transmit it literally, you have to encode it with
%26
:Most programming languages provide a function to do so. (e.g. JavaScript, PHP). The best thing is to encode the whole URL.
$to 必须是 urlencoded,但请注意,您向任何人提供了重定向脚本,因此任何网络钓鱼者都可以使用它.
因此,最好将 url 存储在数据库中并仅传递标识符。
$to must be urlencoded, but note that you giving a redirect script to anyone, so, any phisher can use it.
So, it would be better to store urls in the database and pass only an identifier.
尝试使用base64对to URL进行编码,然后在您展示的示例中将其解码,然后再将其传递到标头:)
try encoding the to URL in base64 and then in the example that u have shown decode it before you pass it to the header :)
对它进行编码
urlencode it
我之前遇到过同样的问题,这就是我所做的:
现在您可以使用 $new_to 变量。
当然,如果您将其用于生产环境,我建议按照其他答案的建议对网址进行编码。我用它来测试curl脚本。以这种方式获取变量有很多缺陷,所以要小心。
I ran into the same problem before, this is what I did:
Now you can use the $new_to variable.
Of course if you're using this for production environment, I would recommend encoding the url as the other answers advised. I was using it for testing curl script. getting the variable this way has lots of flaws, so be careful.
您可以使用名为“html_entity_decode”的函数
单击此处了解更多信息关于此函数
或使用md5函数对URL进行加密,然后在将其放入变量时对其进行解密。
我希望这可以帮助你
You can use a Function called "html_entity_decode"
Click Here for more information about this function
or use md5 function to encrypt the URL and then decrypt it when you put it into a varriable.
I hope this can help you