gpt4 book ai didi

php - 包含 javascript 时出现错误 403 Forbidden

转载 作者:行者123 更新时间:2023-11-28 09:24:32 26 4
gpt4 key购买 nike

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

但是,如果我从外部 URL 获取编写的 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);
} ?>
<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 文件的读取权限。

关于php - 包含 javascript 时出现错误 403 Forbidden,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14567286/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com