我有一个登录功能,我想返回一个变量的值,如果假$变量值:PHP函数返回虚假和不工作
function login($email, $password, $mysqli) {
[...]
// check if username exists
if ($stmt->num_rows == 1) {
// check
if ($db_password == $password) {
//check
} else {
// Invalid password
$error = '2';
return false;
} else {
// No user exists.
$error = '1';
return false;
这是的process_login
// the login function is included in this page
if (login($email, $password, $mysqli) == true) {
// Login success
header('Location: /index.php');
} else {
// Login failed
header("Location: /login.php?error=$error");
}
我想要函数返回错误变量的值,但它不起作用。
怎么回事?
谢谢!
我缺少的东西,它会只能传递?如果你想返回错误变量的值,使用'return $ error;'。 – Barmar 2014-10-03 22:50:18
最佳实践:不要告诉用户它的用户名或密码是否有误。如果你发出太多的信息,攻击者可以集中攻击。如果登录失败,只需从函数中返回'false'即可。 – 2014-10-03 22:51:39
你说得对,谢谢你的提示! – 2014-10-03 22:54:18