当有人登录时,我很难重定向到主页。我成功完成了登录表单,但似乎什么也没发生,我只是停留在同一页面上。我无法发现错误,任何帮助将不胜感激。谢谢。
<?php
include("scripts/connect.php");
$form = "<form action='home.php' method='post'>
<table>
<tr>
<td>Email:</td>
<td><input type='text' name='email' class='textbox' size='35'></td>
<td><a href='register.php'>Register?</a></td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='password' class='textbox' size='35'></td>
<td><input type='submit' name='login' value='Login' class='button' alt='Login'></td>
</tr>
</table>
</form>";
if ($_POST['login']){
$email = strip_tags($_POST['email']);
$password = strip_tags($_POST['password']);
if ($email && $password){
require("scripts/connect.php");
$pass = md5(md5($password));
$query = mysql_query("SELECT * FROM users WHERE email='$email' AND password='$pass'");
$numrows = mysql_num_rows($query);
if ($numrows == 1){
$row = mysql_fetch_assoc($query);
$dbid = $row['uid'];
$dbuser = $row['name'];
$_SESSION['name'] = $dbuser;
$_SESSION['userid'] = $dbid;
header("profile.php?uid=$userid");
}
else
echo "Your login information was incorrect! $form";
}
else
echo "You did not fill in the entire form! $form";
}
else
echo "$form";
?>
标头中的会话变量。
<?php
session_start();
$name = $_SESSION['name'];
$userid = $_SESSION['userid'];
?>