PHP计数器文件和页面转发


PHP counter file and page forwarding

所以我写这段代码,让你得到转发到一个特定的页面,如果你是第一个点击链接,或者你被发送回原始页面后显示一个消息,如果你不是什么初学者的错误我做?

<?php
$count = file_get_contents('counter.txt');
$count = trim($count);
if ($count="0")
{
$count = $count + 1;
$fl = fopen("counter.txt","w+");
fwrite($fl,$count);
fclose($fl);
header("Location: newpage.html");
}
else
{
fclose($fl);
echo "Sorry but the item has already been sold out";
header("Location: oldpage.html");
}
?>

对于延迟,您可以通过两种不同的方式来实现。第一种是使用PHP头文件(就像你现在做的那样),但是把它改成这样:

<?php
header("refresh:5;url=oldpage.html");
echo "Sorry but the item has already been sold out";
?>

另一种方法是回显一段HTML代码,meta-refresh:

 <?php
 echo '<meta http-equiv="refresh" content="2;url=oldpage.html">';
 echo "Sorry but the item has already been sold out";
 ?>

在这两个示例中,5是到刷新的秒数。尝试每一个,看看是否符合你的需要。

这可能是我不熟悉的语法,但是我的脚本中从来没有

<? code

我只使用

<? 

也因为你没有延迟我们的头标记,用户将不会看到上面的先前回显语句。它会在页面有时间完全输出之前自动重定向。