我是PHP新手,并且遇到了我的登录脚本问题,我花了几个小时的时间查看并找不到我要出错的地方。PHP登录表单失败
每当我尝试登录时,我都会按照下面的代码与“输入的电子邮件地址和密码与文件中的电子邮件地址和密码不匹配,或者您尚未激活您的帐户”声明相迎。电子邮件地址和密码存储在数据库中,并使用我的注册和激活脚本输入,这两个脚本都正常工作,并且还通过MySQL连接脚本连接到我的数据库,并使用配置脚本。
我实际上已经建立了这个脚本基于我一直在采取哪一个现在有点关注的课程!
如果有人对我出错的地方有什么建议,我会非常感激。
非常感谢提前!
<?php # login.php
include ('./includes1/headerregistration.html');
require_once ('./includes1/config.php');
$page_title = 'Login';
if (isset($_POST['submitted'])) { // Check if the form has been submitted.
require_once ('./mysql_connect.php');
// Validate the email address.
if (!empty($_POST['email'])) {
$e = escape_data($_POST ['email']);
}
else {
echo '<p><font color="red"size="+1"> You forgot to enter your email address!
</font></p>';
$e = FALSE;
}
// Validate the password.
if (!empty($_POST['pass'])) {
$p = escape_data($_POST ['pass']);
}
else {
$p = FALSE;
echo '<p><font color="red"size="+1"> You forgot to enter your password!
</font></p>';
}
if ($e && $p) { // If everything's OK.
// Query the database.
$query = "SELECT id, first_name FROM Jobseekers WHERE (email='$e' AND pass=SHA('$p')) AND active IS NULL";
$result = mysql_query ($query) or trigger_error("Query: $query\n <br />MySQL Error: " . mysql_error());
if (@mysql_num_rows ($result) == 1) { // A match was made.
// Register the values & redirect.
$row = mysql_fetch_array ($result,MYSQL_NUM);
mysql_free_result($result);
mysql_close();
$_SESSION['first_name'] = $row[1];
$_SESSION['id'] = $row[0];
// Start defining the URL.
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
// Check for a trailing slash.
if ((substr($url, -1) == '/') OR(substr($url, -1) == '\\')) {
$url = substr ($url, 0, -1); // Chop off the slash.
}
// Add the page.
$url .= '/indexregtest.php';
ob_end_clean(); // Delete the buffer.
header("Location: $url");
exit(); // Quit the script.
}
else { // No match was made.
echo '<p><font color="red"size="+1">Either the email address and password entered do not match those on file or you have not yet activated your account.</font></p>';
}
}
else {
echo '<p><font color="red"size="+1">Please try again.</font></p>';
}
mysql_close();
} // End of SUBMIT conditional.
?>
<h1>Login</h1>
<p>Your browser must allow cookies in order to log in.</p>
<form action="login.php"method="post">
<fieldset>
<p><b>Email Address:</b> <input type="text" name="email" size="20" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p>
<p><b>Password:</b> <input type="password" name="pass" size="20" maxlength="20" /></p>
<div align="center"><input type="submit" name="submit" value="Login" /></div>
<input type="hidden" name="submitted" value="TRUE" />
</fieldset>
</form>
<?php
include ('./includes1/footerregistration.html');
?>
html'font'标记和'mysql_ *'库已被弃用。您是否在注册时加密数据?如果这样比较检查时的加密值。 – julienhaversano
@OP你确定你的数据库是okey吗?您可能有重复的条目 – Sanoob
'AND AND IS NULL'。你的意思是'AND AND IS NOT NULL'? – Sasha