Jump to content

IP


SieRobin

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?
Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
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]
Link to comment
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.
Link to comment
Share on other sites

  • 4 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.