【发布时间】:2010-12-10 19:24:13
【问题描述】:
我遇到了问题。我有这个代码:
$theUrl = $_GET["url"];
include("$theUrl.php");
这样获取url,例如:http://mywebsite.com/index.php?url=test
但是如果有人放进去怎么办:
http://mywebsite.com/index.php?url=http://theirwebsite.com/someEvilscript
如何避免这种情况?我只想执行我服务器上的脚本,而不是来自其他网站的脚本。感谢您的帮助。
【问题讨论】:
-
你的意思是这不会发生?
-
基本上答案很简单。不要做那样的事情。永远不要相信用户输入...
-
@ajreal:它会发生。在您发布的文档中:
if "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be included using a URL... -
是的,但一定有办法解决问题...
-
基本上答案很简单。通过 HTTP 包含是有史以来最愚蠢的事情