Login   Register  
PHP Classes
elePHPant
Icontem

File: example3.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Raphael G.  >  x64 Simple Counter  >  example3.php  >  Download  
File: example3.php
Role: Example script
Content type: text/plain
Description: A simple example
Class: x64 Simple Counter
Count site visits using flat files
Author: By
Last change: Fixed some stuff
Date: 2007-03-13 15:02
Size: 1,090 bytes
 

Contents

Class file image Download
<?php

require_once("x64_simple_counter.php");

?>
<html>
<head>
<title>Example3</title>
</head>
<body>
Please give 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

if(isset($_POST["option"]))
{
    echo 
"<hr/>\n";
    
$counter=new x64_simple_counter('example3_counter_data.php',0);
    if(!
$counter->already_counted())
    {
        
$counter->auto();
        if(!
file_exists("votes.dat"))
        {
            
$votes = array('foo'=>0,'bar'=>0);
        }
        else
        
$votes=unserialize(file_get_contents("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
    {
        
?>Sorry, but you already voted.<?php
    
}
}

?>
</body>
</html>