1

I have created a login screen that checks if the password is correct.

After submitting the login form I get to process.php that has these lines:

if (password_verify($passwordPost, $passwordDB)) {
        $_SESSION['loged_in'] = true;
    } else {
        $_SESSION['loged_in'] = false;
    }
    # when I do a print_r on $_SESSION['loged_in'] it results true
    header('Location:  ../../admin/index.php');

The index page that checks the session (../../admin/index.php)

<?php 
    session_start();
    # when I do a print_r on $_SESSION['loged_in'] here, it results false
    if ($_SESSION['loged_in'] == false) {
        include(PATH_COMPONENTS.'login/index.php'); 
    }
    ?>

How is this possible?

6
  • 2
    Did you start your session_start(); in process.php? Commented Nov 15, 2014 at 15:03
  • 1
    Add error reporting to the top of your file(s) right after your opening <?php tag error_reporting(E_ALL); ini_set('display_errors', 1); see if it yields anything. Plus, make sure session_start(); is loaded in all your PHP files, even in login/index.php Commented Nov 15, 2014 at 15:09
  • No I call it in index.php isn't that enough? or do I need to call the session_start every time I need it? Commented Nov 15, 2014 at 15:11
  • 1
    @RalphSchipper: the session must be started on every page load, where you would like to access the session data. Commented Nov 15, 2014 at 15:12
  • @RalphSchipper Yes you have to start it every time! Otherwise you cannot access it! Commented Nov 15, 2014 at 15:12

1 Answer 1

1

You have to start the session in every file! Like this:

session_start();  //most times at the top of every file

YES, you have to start the session in every file your using it!

Also for error reporting use this:

<?php
    error_reporting(E_ALL);
    ini_set("display_errors", 1);
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.