当我使用*http://*foo字符串在我的页面,我得到错误。
例如:
http://www.myadress.com/process.php?url=http://foo
当我切断http://,它工作。我必须做些什么来使用查询字符串的http://?
我这样使用url:
$address = @$_GET['url'];
$source = file_get_contents($url);
//bla bla
显示404错误。
不改变编码
总是重定向到404错误页面。但当我擦除http://,它的工作。我想知道是否因为。htaccess文件?
这里是。htaccess代码(wordpress经典):
RewriteEngine Off
#test
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index'.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# Use PHP 5.3
Action application/x-hg-php53 /cgi-sys/php53
AddHandler application/x-hg-php53 .php
与url中的所有特殊字符一样,必须对它们进行编码。
根据其内容,您可能需要使用urlencode()
$url = urlencode("http://foo");
echo "http://www.example.com/process.php?url=$url;
// prints
http://www.example.com/process.php?url=http%3A%2F%2Ffoo
您需要用%2F
替换斜杠,如下所示:http://www.myadress.com/process.php?url=http:%2F%2Ffoo
然后PHP将其转换回http://
:echo $_GET["url"]; // echos http://foo
如果http似乎有问题,请尝试这样做:
some.php?url=[s]something.com
然后使用php
$url = str_replace("[s]", "http://", $url);
$source = file_get_contents($url);
您的虚拟主机提供商HostGator出于安全原因拒绝查询字符串包含http:/
的请求。有关更多信息,请参阅此主题。要解决这个问题,可以使用部分URL,将URL放在散列中,应用某种编码,或者将请求作为POST请求并将URL放在body中。