Jump to content

Finding multiple Data base entries with PHP


kevincro

Recommended Posts

<?php
$tablename = 'table';
$user_field = 'username';
$ip_field = 'ip_address';

// add your MySQL connection here

$sql = "SELECT `$user_field`, `$ip_field` FROM `$tablename`";
if ( !$result = mysql_query($sql) ) {
    die('MySQL Error: ' . mysql_error());
}
while ( list($user, $ip) = mysql_fetch_assoc($result) ) {
    echo 'Username: ' . $user . '<br>';
    $sql = "SELECT `$user_field` FROM `$tablename`
            WHERE `$ip_field` = `$ip`
            AND `$user_field` != '$user'
           ";
    if ( !$result2 = mysql_query($sql) ) {
        die('MySQL Error: ' . mysql_error());
    }
    if ( mysql_num_rows($result2) > 0 ) {
        while ( list($user2) = mysql_fetch_assoc($result2) ) {
            echo $user2 . 'has the same IP!<br>';
        }
    } else {
        echo 'No duplicate IP found!<br>';
    }
    echo '<br>';
}
echo 'End of list';
?>

 

Will do the job... just fill in the 3 variables at the top and add your connection. Direct all 4 octet matches are rare... however you might want to adjust the script to test for the first 3 octets plus any 4th. That will give you some 'suspicious' results.

 

PhREEEk

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.