我正在尝试验证我的 php/sql 网页的登录名。
第一个代码显示了 Login.php 的一部分,我在其中获取了两个文本字段、电子邮件和密码,并将它们传递给 authenticate.php
第二个代码显示了我在哪里获取这两个值并尝试处理它们。
我遇到的问题是我每次都被定向到 index.php,即使我在该字段中输入了正确的数据。
任何帮助,将不胜感激。
Login.php 的一部分
<td width="70">Email</td>
<td width="6" align="center">:</td>
<form action="authenticate.php" method="post" name="authenticate_form">
<td><input name="email" type="text" id="email"></td>
</tr>
<tr>
<td width="70">Password</td>
<td width="6" align="center">:</td>
<td><input name="password" type="text" id="password"></td>
</tr>
<tr>
<td width="70">Login</td>
<td width="6" align="center">:</td>
<td>
<input type="submit" name="submit" value="Login" />
</form>
</td>
验证.php
// ----------------------
// Retrieve login information
include("db_info.php");
// ----------------------
$conn = oci_connect($db_user, $db_pwd, '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(Host=asuka.cs.ndsu.nodak.edu)(Port=1521)))(CONNECT_DATA=(SID=asuka)))');
if (!$conn) {
$e = oci_error();
print_r($e);
exit();
}
// ----------------------
// Get POST values
if(isset($_POST['email']) && $_POST['email'] && isset($_POST['password']) && $_POST['password']) {
// Get posted form information and strip out unsafe characters
$email = htmlspecialchars(stripslashes($_POST['email']));
$password = htmlspecialchars(stripslashes($_POST['password']));
} else {
// Illegal access.
// Redirect back to index.php
header("location: index3.php");
exit();
}
// ----------------------
// Authenticate User
// Create query
$sql = "SELECT PASSWORD FROM CUSTOMER WHERE EMAIL = '$email'";
// Create database query statement
$statement_id = oci_parse($conn, $sql);
// Execute query statement
$result = oci_execute($statement_id, OCI_COMMIT_ON_SUCCESS);
$queryResult = oci_fetch_row($statement_id);
//var_dump($queryResult);
// Check for successful authentication
if($password == $queryResult[0]) {
if ($email=="admin@hotmail.com") {
$db_login_status = 2;
header("location: admin.php");
} else {
$db_login_status = 1;
header("location: normal.php");
}
} else {
header("location: fail.php");
}
// ----------------------
// Close connections
oci_free_statement($statement_id);
oci_close($conn);