PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Daniel Thul   Voter   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: The example
Class: Voter
Manage survey to vote on colors
Author: By
Last change:
Date: 18 years ago
Size: 2,705 bytes
 

Contents

Class file image Download
<?
session_start
();
if (
$_SESSION['vote']){
?>
<html>
<head>
<title></title>
<meta name="author" content="Daniel Thul">
<meta name="generator" content="Ulli Meybohms HTML EDITOR">
<meta name="expire" content="0">
</head>
<body text="#000000" bgcolor="#AFAFAF" link="#FF0000" alink="#FF0000" vlink="#FF0000">
<center>Sie haben schon abgestimmt!<br>
Ergebnis:<br>
<?
require("class.vote.php");
$vote = new vote;
?>
<img src="<?=$vote->result_image()?>">
</center>
</body>
</html>
<?
}
else{
?>
<html>
<head>
<title></title>
<meta name="author" content="Daniel Thul">
<meta name="generator" content="Ulli Meybohms HTML EDITOR">
<meta name="expire" content="0">
</head>
<body text="#000000" bgcolor="#AFAFAF" link="#FF0000" alink="#FF0000" vlink="#FF0000">
<?
$vote
= $_POST['vote'];
if (!
$vote){
?>
<center>
Choose your favorite color to vote!<br>
<form name="Vote" action="example.php" method="POST">
<table cellspacing="0" cellpadding="0">
<tr><td><input type="radio" name="choice" value="red" id="red" checked></td><td><font color="red"><label for="red">Red</label></a></td></tr>
<tr><td><input type="radio" name="choice" value="yellow" id="yellow"></td><td><font color="yellow"><label for="yellow">Yellow</label></a></td></tr>
<tr><td><input type="radio" name="choice" value="blue" id="blue"></td><td><font color="blue"><label for="blue">Blue</label></a></td></tr>
<tr><td><input type="radio" name="choice" value="green" id="green"></td><td><font color="green"><label for="green">Green</label></a></td></tr>
<tr><td><input type="hidden" name="vote" value="TRUE">
<tr><td clospan="2"><input type="submit" value="Vote!"></td></tr>
</table>
</form>
</center>
<?
}
else if (
$choice == "red" || $choice == "yellow" || $choice == "blue" || $choice == "green"){
$choice = $_POST['choice'];
require(
"class.vote.php");
//First you have to create a new object:
$vote = new vote;
//Then you hand over the choice of the visitor to the class
$vote->answer = $choice;
//Now you must put the vote to the others by this function (You need a file named 'vote.txt', to save the votes)
$vote->count_vote();
$_SESSION['vote'] = TRUE;
//Either you can show the solution to your visitor in numbers...
echo $vote->give_result();
//...or a nice chart(You need the file example_image.php)
echo '<img src="';
echo
$vote->result_image();
echo
'">';
}
else{
//If the variable has not the value red, yellow, blue or green our visitor will see this text (If you use this vote for example for the favorite food of your visitor you have of course to change this variable and its check)
echo "Don`t try to trick me!";
}
?>
</body>
</html>
<?
}//End of Session