Jump to content

problem with ips


desithugg

Recommended Posts

problem with ips
umm just today i added a script that only lets 1 person login 1 accoutn at a time
[code]
$ipcheck = $_SERVER["REMOTE_ADDR"];
$stime=date("U")-0;
$ltime=date("U")-60;
mysql_connect("localhost", $my_sql_password, $my_sql_username) or
   die("Could not connect: " . mysql_error());
mysql_select_db("osiris_thugg");

$result = mysql_query("SELECT time FROM online where username = '$user_currently_loged' && ip = '$ipcheck'");
if (!$result) {
   echo 'Could not run query: ' . mysql_error();
   exit;
}
$row = mysql_fetch_row($result);
$loggin = $row[0];
if($loggin == "")
{

mysql_query("INSERT INTO online
(username, ip, time) VALUES ('$user_currently_loged','$ipcheck','$stime') ")
or die(mysql_error()); 
}

mysql_query("update ".$DBprefix."online set time = '$stime' where username = '$user_currently_loged' && ip = '$ipcheck'")
or die(mysql_error());

$result = mysql_query("SELECT count(time) FROM online where username = '$user_currently_loged' and time > '$ltime'");
if (!$result) {
   echo 'Could not run query: ' . mysql_error();
   exit;
}
$row = mysql_fetch_row($result);
$howmany = $row[0];
if($howmany > "1")
{
echo"There are more than 1 people logged in this account at the moment";
exit;
}
[/code]
what this does is checks if the username and ip combination exists in the table 'online'  if it doesnot exist it inserts a new record but if the combination does exist it just updates the previous record updating the time.And if more than 2 ips have been active in the last 60 seconds the user cannot do anything edit profile and stuff so this prevents some cheating.
But some users have firewalls/internet providers taht change ips constantly
[code]
username | IP
Delta Ray | 165.21.155.15
Delta Ray | 165.21.155.13
Delta Ray | 165.21.155.8
Delta Ray | 165.21.155.17
[/code]
and so on see the pattern only the last 1 or 2 numbers are being changed
so he keeps getting the error and cant do anything is there a way i cna just trim of the last 2 numbers or somehting or get by this problem
Link to comment
Share on other sites

Modified from code in the user notes:

[code]<?php
// reverse strrchr() - PHP v4.0b3 and above
function reverse_strrchr($haystack, $needle)
{
  $pos = strrpos($haystack, $needle);
  if($pos === false) {
      return $haystack;
  }
  return substr($haystack, 0, $pos + 1);
}

$full_ip = "165.21.155.17";
echo reverse_strrchr($full_ip, '.'); // will echo "165.21.155"
?>[/code]
Link to comment
Share on other sites

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.