vendredi 4 juin 2021

can't able to implement PHP session at my website

<?php
require 'connect.php';
$email= $_POST['email'];
$password= $_POST['password'];
$query1= "SELECT * FROM reg WHERE email='$email'";
$data1 = mysqli_query($con,$query1);
$rowcount1=mysqli_num_rows($data1);
$query2= "SELECT * FROM reg WHERE password='$password'";
$data2 = mysqli_query($con,$query2);
$rowcount2=mysqli_num_rows($data2);
if($rowcount1==true && $rowcount2==true)
{
    session_start();
    $row=mysqli_fetch_array($data2);
    $_SESSION['email']=$row['email']; 
    $_SESSION['name']=$row['name'];
    $query= "SELECT * FROM reg where name=". $_SESSION['name'];
    $result= mysqli_query($con,$query);
    header("Location:main.php");
 }

the above is the login script for the login form.

<?php
require 'connect.php';
session_start();
if(!isset($_SESSION['email']))
{
  header('location: index.php');
}
?>

The above is the short PHP code that is on the main product page after login. I'm not able to properly implement the session after login.




Aucun commentaire:

Enregistrer un commentaire