快速问题。这两者之间有什么不同吗?
$success = true;
并且
$success = 'true';
我知道它们彼此不是 '
==
',但使用它们有何区别?编辑:我发现在判断 $success 是否为 false 时使用 '===' 取代 '==' 解决了我的问题。我的问题现在是,在像下面这样的情况下,我是否应该只使用字符串,并坚持使用 '=='?
$User->ProcessLogin();
$loginsuccess = $User->ProcessLogin();
if ($loginsuccess == true) {
echo "<big>Success<big><br />";
echo "<p>We are now redirecting you to the member area.</p>";
echo "<meta http-equiv='refresh' content='=2;MyAccountNEW.php' />";
}
elseif ($loginsuccess == false) {
echo "<span class='sorry'><b>Sorry, your account could not be found.</span></b><div id='shopperlogin'> <img class='shopperlogintext' src='images/shopperlogin.png'>
<br />
<form method='post' action='loginNEW.php' name='loginform' id='loginform'>
<fieldset>
<label for='username'>Username:</label><input type='text' name='username' id='username' /><br />
<label for='password'>Password:</label><input type='password' name='password' id='password' /><br />
<input type='submit' name='login' id='login' value='Login' />
</fieldset>
</form></div>";
}
这是课程的一部分...
function ProcessLogin() {
if (!empty($_POST['username']) && !empty($_POST['password'])) {
$username = mysql_real_escape_string($_POST['username']);
$password = md5(mysql_real_escape_string($_POST['password']));
$checklogin = mysql_query("SELECT * FROM users WHERE Username = '".$username."' AND Password = '".$password."'");
if(mysql_num_rows($checklogin) == 1)
{
$row = mysql_fetch_array($checklogin);
$email = $row['EmailAddress'];
$_SESSION['Username'] = $username;
$_SESSION['EmailAddress'] = $email;
$_SESSION['LoggedIn'] = 1;
$this->loggedin = true;
$success = true;
}
else {
$success = false;
}
return $success;
}
}