我一直试图开发一个按钮点击计数器,以更新点击次数,并打开一个新的网页。我已经成功地使脚本在按钮单击计数器上工作,但我的问题是,当我在窗体操作或按钮上的上包含一个锚标记时,单击计数器就停止工作。
下面是php脚本:
<?php
if( isset($_POST['button1']) ) {
incrementClickCount();
}
function getClickCount()
{
return (int)file_get_contents("counter.txt");
}
function incrementClickCount()
{
$counter = getClickCount() + 1;
file_put_contents("counter.txt", $counter);
}
?>
以下是html:
<form action="index.php" method="POST"/>
<a href="#"><input type="button" name="button1" Value="Submit"/></a>
</form>
<div>Submitted Files: <?php echo getClickCount(); ?></div>
发布于 2016-02-09 02:33:00
a
会是-
<form method="POST"/>
<input type="button" name="button1" Value="Submit"/>
</form>
只需在编写完后使用header
重定向即可。
if( isset($_POST['button1']) ) {
incrementClickCount();
header('location:path-to-page');
exit;
}
https://stackoverflow.com/questions/35289679
复制相似问题