0

I really need your help. My php session is not working.

This is my login code.

<?php  
session_start();
include_once('dbcon/connection.php');
if (!isset($_SESSION['username'])) {
    

  if(isset($_POST["login"]))  
      {  
           if(empty($_POST["email"]) || empty($_POST["password"]))  
           {  
                $error = '<label>All fields are required</label>';  
           }  
           else  
           {

              $stmt = $pdo->prepare("SELECT * FROM user_acc WHERE username=:uname AND password =:pword LIMIT 1");
              $stmt->execute(array(':uname'=>$_POST["email"],':pword'=>$_POST["password"]));
              $userRow = $stmt->fetch(); 
              if($userRow > 0)
              {
                 
                        $_SESSION['username'] = $userRow["user_id_session"]; 
                        header('location:dashboard.php');

              }else{
                 $error = '<label>Username or Password is incorrect</label>';  
              }
           }  
      }  
?>

This is my dashboad code.

session_start();
if (!isset($_SESSION['username'])) {
  header("Location: index.php");
}

Not working, it redirects to login page. What is the error and what should i do so that it is working?

PS: it is already working, the SESSION. But only today it is not working. I don't know why. I am not good in php. Sorry for my English.

Abhishek
  • 539
  • 5
  • 25

0 Answers0