开发者

mysql - finding users who login from the same ip

I'm running a dating site and i want to find out which users have more than one profile.

i have a userlog table with (userid, ip address) and i want to find all users who login from the same ip address - i only want the results where more than 1 user logs in from the same ip.

than开发者_JAVA技巧ks in advance.


This sounds like a simple GROUP BY with a HAVING so I'm going to assume this is what you want:

SELECT "ip address"
FROM userlog
GROUP BY "ip address"
HAVING COUNT(*) > 1

This will give you all the IP addresses of those users. To get the actual users:

SELECT "ip address", userid
FROM userlog
WHERE "ip address" IN (
    SELECT "ip address"
    FROM userlog
    GROUP BY "ip address"
    HAVING COUNT(*) > 1
)
ORDER BY "ip address"


Your query would look something like this...

$ip = $_SERVER['REMOTE_ADDR'];
$email = mysql_real_escape_string($_POST[email]);
$password = mysql_real_escape_string($_POST[password]);

$qry = "SELECT * FROM accounts WHERE email = '$email' && password = '$password' && ip = '$ip'";
$result = mysql_query($qry);
if(mysql_num_rows($result) == 1) {
//What you want to do if it matches with an already logged ip
}

Good luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜