Jump to content

Archived

This topic is now archived and is closed to further replies.

SieRobin

IP

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Not understanding here, if I do a query doesn't it technically only pull one result?

Share this post


Link to post
Share on other sites
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_check
if($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

Share this post


Link to post
Share on other sites
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_check
if($ip_check != "")
{
echo"erroe message";
exit;
}
[/code]try this should work its working for me

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.