I found this script in php which counts button clicks and saves them to a txt file.
<?php
if( isset($_POST['clicks']) )
{
clickInc();
}
function clickInc()
{
$count = ("clickcount.txt");
$clicks = file($count);
$clicks[0]++;
$fp = fopen($count, "w") or die("Can't open file");
fputs($fp, "$clicks[0]");
fclose($fp);
echo $clicks[0];
}
?>
<html>
<head>
<title>button count</title>
</head>
<body>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<input type="submit" value="click me!" name="clicks">
</form>
</body>
</html>
what i cant figure out is how to echo the number of button clicks to a different part of the html. i've tried placing:
<?php
echo $clicks[0];
?>
but that does not work. what am i doing wrong? thanks..
file_get_contentsandfile_put_contentsand play with these to get more practice in php and working with files