Jump to content

IP check (Multi)


grlayouts

Recommended Posts

ok i have a php game. and im trying to check all the ip fields i have in the database against each other and report back any that are the same. what i have is.

[code]<?php $title = "Multi Log"; include("header.php"); ?>
 
<?php
if($action == "multi")
{
if($do == "checker")
{
echo "<center>Multi checker works like this: You see two names next to eachother with the same ip-adress, they ar multis.</center>
<br>
<br><table>";
$get_mm = mysql_query("select * from players where ip AND ip!='0' AND ip!='' order by id");
while($mm = mysql_fetch_array($get_mm))
{
echo "<tr><td colspan=2>$mm[id]: $mm[user]</td></tr>";
$get_mmm = mysql_query("select * from players where ip AND ip='$mm[ip]' AND id!='$mm[id]' AND ip!='0' AND ip!=''");
while($mmm = mysql_fetch_array($get_mmm))
{
echo "<tr><td>&nbsp;&nbsp;&nbsp;</td><td><font color=red>$mmm[id]: $mmm[username]</font></td></tr>";
}
}
    exit;
}
}
?>
<?php include("footer.php"); ?>[/code]

any idea's?
Link to comment
https://forums.phpfreaks.com/topic/26303-ip-check-multi/
Share on other sites

ok... rather than trying to do this with loops and multiple queries, it is much more optimal to try and get the job done with one query. Without a database I can't test this, but something like this should go close.

[code]
<?php
  // connect to database
  $sql = "SELECT username, COUNT(ip) AS ipcnt FROM ips GROUP BY ip";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result) > 0) {
      while ($row = mysql_fetch_assoc($result)) {
        if ($row['ipcnt'] > 1)) {
          echo "{$row['username']} has {$row['ipcnt']} ips addresses.</br />";
        }
      }
    }
  }
?>
[/code]

As I said, this is untested and can probably still be optimised further, but it should give you the idea.
Link to comment
https://forums.phpfreaks.com/topic/26303-ip-check-multi/#findComment-120355
Share on other sites

Archived

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

×
×
  • 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.