我有一个页面,希望一直更新文件中的某个值。
基本上,我有一个脚本将一些数据保存到txt文件中,然后我想在网页上显示这些数据。文本文件中的数据每20秒左右会更新一次。
一开始可以正常运行约3分钟左右,然后页面停止更新。有什么想法是为什么会发生这种情况?
基本上,我有一个脚本将一些数据保存到txt文件中,然后我想在网页上显示这些数据。文本文件中的数据每20秒左右会更新一次。
一开始可以正常运行约3分钟左右,然后页面停止更新。有什么想法是为什么会发生这种情况?
function updatepot(elementid) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById(elementid).innerHTML = this.responseText;
}
};
xmlhttp.open("GET", "../readData.php?q=" + elementid, true);
xmlhttp.send();
}
function updatePots()
{
updatepot("pot0");
}
function keeprunning()
{
setTimeout(updatePots, 1000);
keeprunning();
}
<?php
// get the q parameter from URL
$file = $_REQUEST["q"] . ".txt";
$myfile = fopen("potData/".$file, "r") or die("Unable to open file!");
$myData;
while(!feof($myfile)) {
$myData = $myData . fgets($myfile);
}
fclose($myfile);
echo $myData;
?>
fopen("potData/".$file, "r")
这是一个安全漏洞。$file
可能包含..
,这就意味着可以进入上级目录,因此恶意用户不仅限于读取potData
目录中的文件。如果他们可以猜测到相对文件路径,他们可以读取 PHP 用户具有读访问权限的任何.txt
文件。 - David Knipe