当我运行此脚本时,我试图通过标头将会话重定向到 location:index.php 来回显会话变量($email),但它只是回显会话值(数字 1)而不是电子邮件地址,我可以不知道为什么。有任何想法吗?谢谢。
<?php
session_start();
if (isset($_POST['email'], $_POST['password'])) {
$email = $_POST['email'];
$password = $_POST['password'];
if ($email && $password) {
$connect = mysql_connect("localhost", "root", "") or die("Could not connect");
mysql_select_db("test") or die("could not find database");
$query = mysql_query("SELECT * FROM users WHERE email='$email'&&
password= md5('$password')");
$numrows = mysql_num_rows($query);
if ($numrows != 0) {
$_SESSION["email"] = $email;
session_write_close();
header("location:index.php");
Die();
}
else
echo ("not a user");
}
else
echo("enter both fields");
}
?>
<html>
<form action='edit1.php' method='POST'>
<table align='right' bgcolor='blue'>
<tr>
<td>Email
</td>
<td>Password
</td>
</tr>
<tr>
<td><input name='email' type='text'>
</td>
<td><input name='password' type='password'><td>
<input type='submit' value='login'>
</td>
</tr>
</table>
</form>
</html>
//index.php file
<?php
session_start(); {
echo $_SESSION['email'] or die('fail'); {
}
}
?>