Location: PHPKode > scripts > x64 Simple Counter > x64-simple-counter/example4.php
<?php

require_once("x64_simple_counter.php");

$counter=new x64_simple_counter('example4_counter_data.php',0);
?>
<html>
<head>
<title>Example4</title>
</head>
<body>
<?php

if(!$counter->already_counted())
{

?>
Please tell us your opinion:<br/>
<form action="example3.php" method="post">
Foo <input type="radio" name="option" value="foo"><br/>
Bar <input type="radio" name="option" value="bar"><br/>
<input type="submit">
</form>
<?php

}
else
{
	$votes=unserialize(file("votes.dat"));
	foreach ($votes as $option=>$count)
	{	
		echo "Total votes for $option: $count<br/>";	
	}
}

if(isset($_POST["option"]))
{
	echo "<hr/>\n";
	if(!$counter->already_counted())
	{
		$counter->auto();
		$votes=unserialize(file("votes.dat"));
		if($_POST["option"]=="foo"||$_POST["option"]=="bar")
		{
			$continue=true;
			$votes[$_POST["option"]]++;
		}
		else
		{
			$continue=false;
			echo "Don't try to hack us! now, don't think that you can still vote anymore!<br/>";
		}
		if($continue)
		{
			$fp=fopen("votes.dat","wb");
			fwrite($fp,serialize($votes));
			fclose($fp);
			echo "Thanks for voting.<br/>";
		}
	}
	else
	{
		?>Don't try to cheat!<?php
	}
}

?>
</body>
</html>
Return current item: x64 Simple Counter