【问题标题】:URL cutsoff at special characters when doing GET in PHP在 PHP 中执行 GET 时在特殊字符处截断 URL
【发布时间】:2016-06-22 10:04:08
【问题描述】:

我有这个域名

https://test.com/?url=https://google.com/search?q=#ie7&rls=login.microsoft:en-US:IE-Address&ie=&oe=#

这是代码:

<?php
 //check if the url parameter exists 
 if(isset($_GET['url'])) $url=$_GET['url'];
 else $url=FALSE;
?>

If I use this in the html
<?=(!$url) ? '' : $url ?>

我得到的输出会以特殊字符(如 # 或 & 等)截断,并变成这样,例如 https://google.com/search?q=# 我尝试了 urlencode/decode 但无法弄清楚

【问题讨论】:

  • 您尝试获取锚散列。你不能在 php.ini 中做到这一点。 See this answer in stackoverflow
  • 谢谢,其他字符,如 & 和空格等。# 只是我用来测试的一个例子,但通常问题在于 & 和空格。

标签: php html url


【解决方案1】:

如果你需要在?url=之后,你可以试试这个:

$url = $_SERVER['REQUEST_URI'];  
$url2 = substr($url, strpos($url, '?url')+5);
$url = substr($url, strpos($url, '?url'));  
print($url); // url?=https://..etc
print($url2); // https://..etc  

【讨论】:

  • 像魅力一样工作!谢谢!
【解决方案2】:

您想在

之后输出完整的域
https://test.com/?url=

到最后,得到https://google.com/search?q=#ie7&amp;rls=login.microsoft:en-US:IE-Address&amp;ie=&amp;oe=# 对吧?

所以如果这个问题解决了,你可以这样做:

echo substr($url, 22);

【讨论】:

    猜你喜欢
    • 2010-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-21
    • 1970-01-01
    • 1970-01-01
    • 2011-03-25
    • 2015-05-08
    相关资源
    最近更新 更多