【问题标题】:Error 403 Forbidden when including javascript包含 javascript 时禁止出现错误 403
【发布时间】:2013-01-29 01:09:56
【问题描述】:

我有几段代码应该从另一个网站获取表单。标头中的 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) 告诉我。

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

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

【问题讨论】:

    标签: php javascript ajax


    【解决方案1】:

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

    【讨论】:

    • 有趣。我目前正在 Windows 上的 localhost(安装了 XAMPP)上运行它。我的印象是没有需要用 windows 更改的权限。
    猜你喜欢
    • 2016-01-12
    • 2013-07-19
    • 1970-01-01
    • 2021-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-19
    • 2015-01-09
    相关资源
    最近更新 更多