我在制作项目的基本登录脚本方面遇到了麻烦。 登录工作除了我无法解决的一件事:
在我User.php
页面的顶部,我有代码:
<?php
session_start();
if(!$_SESSION['email']){
header("location:Login");
}
?>
哪个工作正常,但我登录的其他脚本我有这个和
$ _SESSION似乎没有初始化或注册,我做了一些根本错误的事情吗?
未显示数据库详细信息,但他们已在此部分之前
// username and password sent from form
$email=$_POST['email'];
$pass=$_POST['pass'];
// To protect MySQL injection (more detail about MySQL injection)
$email = stripslashes($email);
$pass = stripslashes($pass);
$email = mysql_real_escape_string($email);
$pass = mysql_real_escape_string($pass);
$sql="SELECT * FROM $tbl_name WHERE email='$email' and pass='$pass'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
$row=mysql_fetch_array($result);
// Register $myusername, $mypassword and redirect to file "login_success.php";
$_SESSION['fname'] =$row['fname'];
$_SESSION['lname'] =$row['lname'];
$_SESSION['email'] =$_POST['email'];
$_SESSION['id'] =$_POST['id'];
$sow = $row['id'];
header("location:User.php?id=$sow");
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
?>