我嘗試登錄並設置會話id.Below代碼沒有驗證登錄成功,並沒有設置會話id.Plz幫助。爲什麼登錄和會話ID沒有在這個功能中設置?
public $userid;
function login()
{
$pwdHasher = new PasswordHash(8, FALSE);
if(isset($_POST['logging']) AND !empty($_POST['logging'])){
$email=mysqli_real_escape_string($this->db->connection ,$_POST['email']);
$pass=mysqli_real_escape_string($this->db->connection ,$_POST['pass']);
$sql=mysqli_query($this->db->connection,"SELECT * FROM user where email='$email' AND password='$pass'");
$numrows=mysqli_num_rows($sql);
$resid=mysqli_fetch_array($sql);
$checked = $pwdHasher->CheckPassword($pass,$numrows);
if($checked){
$this->userid=$_SESSION['id']=$resid['id'];
$this->login=TRUE;
echo "u r logedin.Plz click here to go to main area<a href='main.php'>main</a>";
}
else{
echo "username r password is wrong";
$this->login=FALSE;
}
}
}
使用$ _SESSION之前使用session_start()。 –