1

我有几段代码应该从另一个网站获取表单。标头中的 php 清理 URL 中的 GET 字符串。基本上我有一个页面:order.html,如果我像这样粘贴整个 javascript 函数,它就可以工作:

<?php  if (isset($_GET['url'])) {
            echo file_get_contents("http://".sanitizeString($_GET['url']));
        }
function sanitizeString($var) {
    $var = strip_tags($var);
    $var = htmlentities($var);
    return stripslashes($var);
} ?>


<html>
<body>
<p>html text still displays</p>
<script>
document.write("<div id='info'></div>");
nocache = "&nocache=" + Math.random() * 1000000
request = new ajaxRequest()
request.open("GET", "<?php echo basename($_SERVER['SCRIPT_FILENAME']); ?>?url=platform.leedhub.com/merchants/form.php?merchant_id=<?php echo $_GET['merchantid']; ?>&margin=<?php echo $_GET['affiliateid'] ?>&padding=<?php echo $_GET['URL'] ?>" + nocache, true);
request.onreadystatechange = function()
{
    if (this.readyState == 4)
    {
        if (this.status == 200)
        {
            if (this.responseText != null)
            {
                document.getElementById('info').innerHTML =
                this.responseText
            }
            else alert("Ajax error: No data received")
        }
        else alert( "Ajax error: " + this.statusText)
    }
}
request.send(null)
    function ajaxRequest()
    {
        try
        {
            var request = new XMLHttpRequest()
        }
        catch(e1)
        {
            try
            {
                request = new ActiveXObject("Msxml2.XMLHTTP")
            }
            catch(e2)
            {
                try
                {
                    request = new ActiveXObject("Microsoft.XMLHTTP")
                }
                catch(e3)
                {
                    request = false
                }
            }
        }
        return request
    }
</script>
</body>
</html>

但是,如果我使用编写的 javascript 并从外部 url 包含它,它将无法工作。

<?php  if (isset($_GET['url'])) {
echo file_get_contents("http://".sanitizeString($_GET['url']));
}
function sanitizeString($var) {
$var = strip_tags($var);
$var = htmlentities($var);
return stripslashes($var);
} ?>
<p>html text still displays</p>
<html>
<body>
<script src="urlget.js"></script>
</body>
</html>

我收到 403 禁止错误。它从 request.send(null) 告诉我。

禁止访问 您无权访问请求的对象。它要么是读保护的,要么是服务器不可读的。

你知道我该如何解决这个问题吗?我需要将脚本作为外部文件,以便可以将其包含在多个网站上。

4

1 回答 1

0

我认为这是一个文件系统权限问题。您必须确保 Web 服务器对该urlget.js文件具有读取权限。您必须找出哪个用户正在运行 Web 服务器的工作线程,并授予该用户对urlget.js文件的读取权限。

于 2013-01-28T17:09:56.173 回答