SieRobin Posted August 21, 2006 Share Posted August 21, 2006 Hello all, I'm having some trouble with duplicate IP addresses. What I'm trying to do is limit the user to one account per IP address, the way I've tried to work it out obviously doesn't work or I'd actually just do it that way. Here's my script of what I have, not that it works but, it may spark ideas on the easiest way this can be done.[code]$dupip=mysql_query("SELECT IP from users"); $dupip2=mysql_fetch_array($dupip); $IP=$_SERVER['REMOTE_ADDR'];if($IP==$dupip2['IP']) { print "<br><table class='table'><tr class='headline'><td><center>Register</center></td> <tr class='mainrow'><td><center>There is already an account containing that IP address, one account per IP address. <a href='index.php'>Login</a> to your already existing account.</center></td></tr></table>"; }[/code]All it really does is after it's done all the checking if the username is taken so on and so forth, is it logs your IP into the database, then if you try and sign up again under the same IP, it won't allow you to. I think it has something to do with my array, would an assoc do anything different or do I need a while loop? Link to comment https://forums.phpfreaks.com/topic/18157-ip/ Share on other sites More sharing options...
tomfmason Posted August 21, 2006 Share Posted August 21, 2006 I would do it like this[code=php:0]$ip = $_SERVER['REMOTE_ADDR'];$sql = sprint_f("SELECT COUNT(*) AS `ip_check` FROM `users` WHERE `ip`= '%s'", $ip);$res = mysql_query($sql) or die(mysql_error());$check_ip = mysql_result($res, 0, 'check_ip');if ($check_ip !== 0) { echo "Your error message"; include("somepage.php"); exit(1);}//continue with the script[/code]I would place this before you process any other data.Hope this helps,Tom Link to comment https://forums.phpfreaks.com/topic/18157-ip/#findComment-77861 Share on other sites More sharing options...
SieRobin Posted August 21, 2006 Author Share Posted August 21, 2006 Not understanding here, if I do a query doesn't it technically only pull one result? Link to comment https://forums.phpfreaks.com/topic/18157-ip/#findComment-77864 Share on other sites More sharing options...
desithugg Posted August 21, 2006 Share Posted August 21, 2006 try this should be a little simpler[code]$ip = $_SERVER['REMOTE_ADDR'];$query = ("SELECT ip AS `ip_check` FROM `users` WHERE `ip` = '$ip' limit 1);$result = mysql_query($query) or die(mysql_error());$ip_check = $row['ip_check']; //sets a variable for the row ip_checkif($ip_check != ""){echo"erroe message"exit;}[/code]if there is a username/account with the ip address that is being ouput by the users computer is will get some data but if not the varialbe $ip_check will be blank so when it is not blabk it gives the error message (sorry if im confusing) and using limit 1 will only pull out one result Link to comment https://forums.phpfreaks.com/topic/18157-ip/#findComment-77866 Share on other sites More sharing options...
SieRobin Posted August 21, 2006 Author Share Posted August 21, 2006 Doesn't work. Link to comment https://forums.phpfreaks.com/topic/18157-ip/#findComment-77869 Share on other sites More sharing options...
desithugg Posted August 21, 2006 Share Posted August 21, 2006 o.o s[quote author=SieRobin link=topic=105013.msg419214#msg419214 date=1156131768]Doesn't work.[/quote]o.o srry i was missing the ";" after that echo[code]$ip = $_SERVER['REMOTE_ADDR'];$query = ("SELECT ip AS `ip_check` FROM `users` WHERE `ip` = '$ip' limit 1);$result = mysql_query($query) or die(mysql_error());$ip_check = $row['ip_check']; //sets a variable for the row ip_checkif($ip_check != ""){echo"erroe message";exit;}[/code]try this should work its working for me Link to comment https://forums.phpfreaks.com/topic/18157-ip/#findComment-77870 Share on other sites More sharing options...
SieRobin Posted August 21, 2006 Author Share Posted August 21, 2006 Isn't there just an easier way to do this? Seems so.. I had it working but it was only pulling the first user from the database, I just want it to check every person. Link to comment https://forums.phpfreaks.com/topic/18157-ip/#findComment-77871 Share on other sites More sharing options...
SieRobin Posted August 21, 2006 Author Share Posted August 21, 2006 Yep and like I said there was, there was :P I found a way to do it easier, just a while loop and an exit.. BAM done. Thank you for the help though :] Link to comment https://forums.phpfreaks.com/topic/18157-ip/#findComment-77872 Share on other sites More sharing options...
desithugg Posted August 21, 2006 Share Posted August 21, 2006 o.o lol can you show me the way lol.im thinking of dog the same thing with my rpg.umm i was gonna try an array not sure if it will work tough[code]$query = "SELECT ip as ip_check FROM users"; $result = mysql_query($query) or die(mysql_error());while($row = mysql_fetch_assoc($result)){$ip_check[] = $row['ip_check'];$ip_check_2 = explode(", ", $ip_check);$ip_check3 = array($ip_check2);if (in_array($ip, $ip_check3)) { echo "error message"; exit;}[/code]well btw. can u look at my thread no1s reading it im really stuck[url=http://www.phpfreaks.com/forums/index.php/topic,105015.0.html]http://www.phpfreaks.com/forums/index.php/topic,105015.0.html[/url] Link to comment https://forums.phpfreaks.com/topic/18157-ip/#findComment-77873 Share on other sites More sharing options...
tomfmason Posted August 21, 2006 Share Posted August 21, 2006 [quote author=SieRobin link=topic=105013.msg419209#msg419209 date=1156130785]Not understanding here, if I do a query doesn't it technically only pull one result?[/quote]What my code does is check all of ip rows in the database to see if there is a match. If there is a match then it will echo the error message. This is a faster and or better way of doing this. If you are planning on having alot of members then I would recomend that you do it that way. Link to comment https://forums.phpfreaks.com/topic/18157-ip/#findComment-77877 Share on other sites More sharing options...
ToonMariner Posted August 21, 2006 Share Posted August 21, 2006 Becareful!Peoples IP addresses change so what you are attempting to do could potentially never allow a user to access their account again once their ISP has renewed addresses. Link to comment https://forums.phpfreaks.com/topic/18157-ip/#findComment-77957 Share on other sites More sharing options...
SieRobin Posted September 14, 2006 Author Share Posted September 14, 2006 It limits the accounts used per IP address, usually they don't renew that often in most senses, I already tested it with the 85 members I have. Link to comment https://forums.phpfreaks.com/topic/18157-ip/#findComment-91491 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.