我试图阻止来自同一 IP 的多个帐户:
if (! empty($_SERVER['HTTP_CLIENT_IP']))
{
$ip = $_SERVER['HTTP_CLIENT_IP'];
}
elseif (! empty($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip = $_SERVER['REMOTE_ADDR'];
}
$stmt = $db->prepare("SELECT 1 FROM users WHERE ip = :ip");
$stmt->bindParam(':ip', $ip, PDO::PARAM_STR);
$result = $stmt->execute();
$row = $stmt->fetch();
if ($row)
{
die("Only one account per IP is allowed !");
}
这行得通,但是如果我想允许每个 IP 有两个帐户怎么办?我试过了:
$stmt = $db->prepare("SELECT * FROM users WHERE ip = :ip");
$stmt->bindParam(':ip', $ip, PDO::PARAM_STR);
$result = $stmt->execute();
$row = $stmt->fetch();
if ($row > 1)
{
die("Only one account per IP is allowed !");
}
不工作。不允许使用第二个帐户。