skip to Main Content

I am using this

if (!isset($_SESSION['login_success'])):  header("Location:index.php"); 

die();
endif;

It does work in local host but after i uploaded the site in server, when session expires it stays in the same page and not redirect to index or login page.

2

Answers


  1. Are You sure you initialize sessions before that your code.

    Try this at very top of script and let me know how it goes.

        //initialize session
        session_start();
        //set session
        if(!isset($_SESSION['login_success']) || (trim($_SESSION['login_success']) == '')) {
                header("location: index.php");
                exit();
            }
    // Your template file is included below
    include_once 'template/top.php';  
    
    Login or Signup to reply.
  2. You will have to check if session is set first before including your template/top.php file. I have updated my answer to that effect. Put that code at the very top of your page –
    Nancy Moore
    Feb 16 at 8:49

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search