Login   Register  
PHP Classes
elePHPant
Icontem

File: example4.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  >  example4.php  >  Download  
File: example4.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: 7 years ago
Size: 1,431 bytes
 

Contents

Class file image Download
<?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 give us your opinion:<br/>
<form action="example4.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
{
    if(!
file_exists("votes2.dat"))
    {
        
$votes = array('foo'=>0,'bar'=>0);
    }
    else
    
$votes=unserialize(file_get_contents("votes2.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();
        if(!
file_exists("votes2.dat"))
        {
            
$votes = array('foo'=>0,'bar'=>0);
        }
        else
        
$votes=unserialize(file_get_contents("votes2.dat"));
        if(
$_POST["option"]=="foo"||$_POST["option"]=="bar")
        {
            
$continue=true;
            
$votes[$_POST["option"]]++;
        }
        else
        {
            
$continue=false;
            echo 
"Don't try to hack us!, don't think you can still vote!<br/>";
        }
        if(
$continue)
        {
            
$fp=fopen("votes2.dat","wb");
            
fwrite($fp,serialize($votes));
            
fclose($fp);
            echo 
"Thanks for your vote.<br/>";
        }
    }
    else
    {
        
?>Don't try to cheat!<?php
    
}
}

?>
</body>
</html>