I made login page with database and home page I tied the database with login page... connection code:
function login ($email,$password){
$con=mysqli_connect("localhost","root","","cv");
$sql = "SELECT * FROM `user`
where `email` = '$email' && `password`= $password ";
$q=mysqli_query($con,$sql);
$res = mysqli_fetch_assoc($q);
return $res ;
}
and i want to use session on it so i wrote a simple code in login page :
<?php
session_start ();
include "lib/user.php";
if(isset($_POST["email"])){
$email =$_POST["email"];
$password=$_POST["password"];
$res= login($email,$password);
if(!empty ($res)){
$_SESSION[`user`] =$res ;
header ('LOCATION:home.php');
}else{
$erorrrr='email or password is not found!!';
}
}
?>
and this one in home page :
?php
session_start ();
if (empty($_SESSION['user'])){
header("LOCATION:login.php");
}
?>
finally the page never loged in !!Although the email and password are in the database... i think this problem just in $_SESSION
how can i fix it and take sessions from users
source https://stackoverflow.com/questions/73673807/session-and-login-page-with-php
No comments:
Post a Comment