I have a rating script that logs users' IPs so they can't rate the file more than once. However, every time I rate the file to test it, my $ip changes with the ip2long() function. What's up? Here's my code:
<?php
require('connect.php');
$sheetID = $_GET["id"];
$rating = $_GET["rating"];
$ip= $_SERVER['REMOTE_ADDR'];
$ip = ip2long($ip);
$checkIPQuery = mysql_query("SELECT * FROM ratings WHERE sheetID = '$sheetID' and INET_NTOA(ip) = '$ip'");
$doesIPExist = mysql_num_rows($checkIPQuery);
if ($doesIPExist == 0) {
mysql_query("INSERT INTO ratings (sheetID, rating, ip) VALUES ($sheetID, $rating, $ip)");
echo " $ip
<script>setTimeout(function(){location.href = '../sheets.php?id=$sheetID'},1);</script>";
}
else
echo 'You have already rated this image!';
?>
And then for the check if the user has rated script:
$id = $_GET['id'];
$ip=$_SERVER['REMOTE_ADDR'];
$ip = ip2long($ip);
$checkIPQuery = mysql_query("SELECT * FROM ratings WHERE sheetID = '$id' and INET_NTOA(ip) = '$ip'");
$doesIPExist = mysql_num_rows($checkIPQuery);
Here's what I've done:
- Changed the field to an unassigned INT when the $ip wouldn't go into a varchar(15)
- I have added the ip2long() function because i changed the ip field to an INT
- I then added the INET_NTOA(ip) to read the ip2long() INT
Any help would be appreciated. Thanks!
Edit: These scripts work fine if I set the $ip to 3 for example.