我有一个读取 PHP 文件的简单代码脚本,当它被更改时,它应该在页面上显示 CHANGED,我将更改它以刷新页面或更改内容。现在,它显示内容,该功能重复一两次,然后什么都不显示。有什么帮助吗?
这是代码:
<?php
$handle = fopen("../chat/real/chatserver.php", "r");
$contents = fread($handle, filesize("../chat/real/chatserver.php"));
fclose($handle);
$newcontents = $contents;
echo $contents;
?>
<script type="text/javascript">
checkchanged();
function checkchanged() {
document.write("<?php $handle = fopen('../chat/real/chatserver.php', 'r');
$newcontents = fread($handle,filesize('../chat/real/chatserver.php'));fclose($handle);?>");
document.write("<?php if(!($contents==$newcontents)){echo 'Changed';} ?>");
setTimeout('checkchanged()',3000);
}
</script>
谢谢您的帮助