[英]Error 403 Forbidden when including javascript
我有幾段代碼應該從另一個網站獲取表單。 標頭中的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)告訴我的。
禁止訪問您沒有訪問所請求對象的權限。 服務器對其進行了讀保護或不可讀。
您知道我該如何補救嗎? 我需要將該腳本作為外部文件,以便可以將其包含在多個網站上。
我認為這是文件系統權限問題。 您必須確保Web服務器對urlget.js
文件具有讀取訪問權限。 您必須找出哪個用戶正在運行Web服務器的工作程序,並向該用戶授予urlget.js
文件的讀取權限。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.