我想知道如何检查是否存在,但检查是否相同。这是我的代码:
$user = $_COOKIE["c_user"];
$ip = $_SERVER['REMOTE_ADDR'];
$salt = $_COOKIE["c_salt"];
$chk_salt = mysql_fetch_array(mysql_query("SELECT * FROM `table1` WHERE `Salt`='$salt'"));
if ($chk_salt == '0') {
die("Get out!");
}
else {
echo "Welcome ".ucwords($user);
}
答案 0 :(得分:0)
$host = 'your_mysql_host';
$dbname = 'your_db_name';
$user = 'username';
$pass = 'password';
try {
$conn = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo 'Error: ' . $e->getMessage().'<br>';
}
$user = $_COOKIE["c_user"];
$ip = $_SERVER['REMOTE_ADDR'];
$salt = $_COOKIE ['c_salt'];
$chckSalt = $conn->prepare("SELECT * FROM table1 WHERE Salt=:salt");
$chckSalt->bindValue(':salt', $salt, PDO::PARAM_STR);
$chckSalt->execute ();
if ($chkSalt->rowCount () == 0) {
die("Get out!");
}
else {
echo "Welcome ".ucwords($user);
}