- Joined
- Sep 12, 2008
- Messages
- 27
- Reaction score
- 0
This script allows you to add a poll to your website.
Put pollimg inside of your images directory and the poll.php inside of your website.
To add it to a part of your website add
to any where.
SQL
Thanks for reading put your flame elsewhere.
Quick fix for blocking people who aren't registered...
Below
Add
Change
to
Sorry for that, if you need one you can just replace yours with the one below.
- 1 vote per IP
- only registerd ingame users may vote
- Displaies percent
- Displaies % as a bar
- Displays total vote
- Displays total votes for each option
- logs date
- uses text imput
- not hard to add more options
- 2 choices default
To view the content, you need to sign in or register
Put pollimg inside of your images directory and the poll.php inside of your website.
To add it to a part of your website add
Code:
<?php include("poll.php"); ?>
SQL
Code:
DROP TABLE IF EXISTS `voteTable`;
CREATE TABLE `voteTable` (
`id` int(11) NOT NULL auto_increment,
`choice1` tinyint(1) NOT NULL default '0',
`choice2` tinyint(1) NOT NULL default '0',
`hasvoted` tinyint(1) NOT NULL default '0',
`ip` varchar(40) NOT NULL default '',
`date` varchar(40) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Thanks for reading put your flame elsewhere.
Quick fix for blocking people who aren't registered...
Below
Code:
$rCheck = mysql_query("SELECT * FROM `accounts` WHERE `lastknownip`='".$ipadress."'") or die(mysql_error());//checks if user is registerd ingame
Code:
$rCheck2= mysql_num_rows($rCheck);
Code:
}elseif($rCheck >= 1){
Code:
}elseif($rCheck2 >= 1){
Sorry for that, if you need one you can just replace yours with the one below.
Code:
<?php
include("config.php");
/* Copy righted 2008 to Duncan Brown use with out concent is prohibited. */
function tep_get_ip_address() {
if (isset($_SERVER)) {
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
} else {
if (getenv('HTTP_X_FORWARDED_FOR')) {
$ip = getenv('HTTP_X_FORWARDED_FOR');
} elseif (getenv('HTTP_CLIENT_IP')) {
$ip = getenv('HTTP_CLIENT_IP');
} else {
$ip = getenv('REMOTE_ADDR');
}
}
return $ip;
}
$aa1 = mysql_query("SELECT * FROM `votetable` WHERE `choice1`='1' AND `hasvoted`=1") or die(mysql_error());//counts choice 1
$aa2 = mysql_query("SELECT * FROM `votetable` WHERE `choice2`='1' AND `hasvoted`=1") or die(mysql_error());//counts choice 2
$a1 = mysql_num_rows($aa1);
$a2 = mysql_num_rows($aa2);
$ipadress = tep_get_ip_address();
$acheck = mysql_query("SELECT * FROM `votetable` WHERE `ip`='".$ipadress."'") or die(mysql_error());//checks in voted
$acheck2 = mysql_num_rows($acheck);
$ftotal1 = mysql_query("SELECT * FROM `votetable` WHERE `hasvoted`='1'") or die(mysql_error());//checks in voted
$ftotal = mysql_num_rows($ftotal1);
$findp1 = (int) (($a1/$ftotal)*100);
$findp2 = (int) (($a2/$ftotal)*100);
$gl1 = (int) (100-$findp1);
$gl2 = (int) (100-$findp2);
if($acheck2 >= 1){
echo "<fieldset><legend><b>Results</b></legend>";
if($a1 >= 1){
echo "<table width=\"286\" border=\"0\"><tr><th scope=\"row\">Whipe: ".$a1."</th><td>".$findp1."%</td>";
echo "<td><img src=\"images/pollimg/bar.gif\" width=\".$findp1.\" height=\"11\"/><img src=\"images/pollimg/ghost.gif\" width=\".$gl1.\" height=\"11\"/><br><td>";
}else{
echo "<table width=\"286\" border=\"0\"><tr><th scope=\"row\">Whipe: 0";
echo "<td><img src=\"images/pollimg/bar.gif\" width=\"1\" height=\"11\"/><img src=\"images/pollimg/ghost.gif\" width=\"99\" height=\"11\"/><br><td>";
}
if($a2 >= 1){
echo "<tr><th scope=\"row\">Keep: ".$a2."</th><td>".$findp2."%</td>";
echo "<td><img src=\"images/pollimg/bar.gif\" width=\".$findp2.\" height=\"11\"/><img src=\"images/pollimg/ghost.gif\" width=\".$gl2.\" height=\"11\"/><br><td></table>";
}else{
echo "<tr><th scope=\"row\">Keep: 0</th>";
echo "<td><img src=\"images/pollimg/bar.gif\" width=\"1\" height=\"11\"/><img src=\"images/pollimg/ghost.gif\" width=\"99\" height=\"11\"/><br><td></table>";
}
echo "Total Votes: ".$ftotal."";
echo "</fieldset>";
}else{
if(!$_POST['vote']){
echo "<fieldset><legend><b>To whipe or not to whipe that is the question!</b></legend><br />";
echo "<form method=\"POST\">";
echo "<center><table border=\"0\" width=\"20\">";
echo "<tr><td align=\"left\" width=\"25%\"><b>Whipe or Keep Please enter one.</b></td><td><input type=\"text\" name=\"choice\" maxlength=\"12\"></td></tr>";
echo "<tr><td></td><td><input type=\"submit\" value=\"Vote!\" name=\"vote\">";
echo "</table></center></form>";
echo "</fieldset>";
}else{
$bVote = mysql_query("SELECT * FROM `voteTable` WHERE `ip`='".$ipadress."'") or die(mysql_error());//checks in voted
$rCheck = mysql_query("SELECT * FROM `accounts` WHERE `lastknownip`='".$ipadress."'") or die(mysql_error());//checks if user is registerd ingame
$rCheck2= mysql_num_rows($rCheck);
$choice = mysql_real_escape_string($_POST['choice']);
$date = date("m/d/Y h:i");
if($choice == ""){
echo "Please supply an choice!";
}elseif($acheck2 >= 1){
echo "You have already voted cheater!!!";
}elseif($rCheck2 >= 1){
if($choice == "whipe" || $choice == "Whipe"){//cehcks for caps or not
$ia = mysql_query("INSERT INTO `voteTable` (`choice1`,`hasvoted`,`ip`,`date`) VALUES ('1','1','".$ipadress."','".$date."')") or die(mysql_error());
echo "You have chosen to have the characters whiped.";
}
if($choice == "keep" || $choice == "Keep"){//checks for caps or not
echo "You have chosen to keep the characters as is.";
$ia = mysql_query("INSERT INTO `voteTable` (`choice2`,`hasvoted`,`ip`,`date`) VALUES ('1','1','".$ipadress."','".$date."')") or die(mysql_error());
}
}else{
echo "fail";
}
}
}
?>
Last edited: