I have a poll script but the only problem it has is that it will let me add more than one vote, I used a basic ip detection but that didn't work. Is there a way of getting the users real IP?
This is what I have right now:
This is what I have right now:
PHP:
<?php
include 'config.php';
mysql_connect("$host", "$user", "$pass") or die(mysql_error());
mysql_select_db("$dbname") or die(mysql_error());
$ip = $_SERVER['REMOTE_ADDR'];
if (trim($ip) == '') {
$ip = $_SERVER['HTTP_CLIENT_IP'];
}
if (trim($ip) == '') {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
$query = mysql_query("select * from vote where ip='$ip'");
$countbans = mysql_num_rows($query);
if($countbans > 0) {
include "results.php";
echo("You have Already Voted!");
}else{
$action = $_GET['action'];
if(!isset($action) || empty($action) || $action !== "addvote"){
echo("<form name='form1' method='post' action='?action=addvote'>
<table width='100%' border='0' cellspacing='2' cellpadding='0'>
<tr>
<td colspan='2'><div align='left'>Do you like my site?</div></td>
</tr>
<tr>
<td width='19%'><input type='radio' name='vote' value='ex'></td>
<td width='81%' bgcolor='#F4F4F4'>It's Excellent!</td>
</tr>
<tr>
<td><input type='radio' name='vote' value='co'></td>
<td bgcolor='#F4F4F4'>Pretty Cool</td>
</tr>
<tr>
<td><input type='radio' name='vote' value='ok'></td>
<td bgcolor='#F4F4F4'>OK</td>
</tr>
<tr>
<td><input type='radio' name='vote' value='ha'></td>
<td bgcolor='#F4F4F4'>Hate It!</td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='Submit' value='Vote!'></td>
</tr>
</table>
</form>");
}elseif($action == "addvote"){
//show result
echo "<p><h4>Thank you For Voting</h4></p>";
$vote = $_POST['vote'];
include 'config.php';
$ip = $_SERVER['REMOTE_ADDR'];
if (trim($ip) == '') {
$ip = $_SERVER['HTTP_CLIENT_IP'];
}
if (trim($ip) == '') {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
mysql_connect("$host", "$user", "$pass") or die(mysql_error());
mysql_select_db("$dbname") or die(mysql_error());
mysql_query("INSERT INTO `vote` (`vote` , `ip` ) VALUES ('$vote', '$ip')");
}
}
?>








