当我运行这个脚本时,我试图通过标题将会话重定向到位置: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'); {
}
}
?>
答案 0 :(得分:3)
正如我在评论中所说,or die
不起作用。删除它。
答案 1 :(得分:0)
删除或死掉('失败')它会正常工作。
函数echo返回void呈现'或die()'无用