For some reason I don’t manage to take some date from one page to another using the $_SESSION-variable.
On my index.php-page is a form where users can login.
I start with (where session_start() is in the inc_admin.php-file):
require_once '../includes/php/inc_admin.php';
if ($_GET['page'] == 'login') {
$action = loginUser($_DB, $_POST['firstname'], $_POST['password']);
}
if(isset($_SESSION["user"])) {
$action .= header('Location: ../admin/index.php');
}
echo $action;
The loginUser-function does set (among other) the $_SESSION:
$user = Leaders::getLogin($_DB, $firstname, $password);
if(!empty($user)) {
$_SESSION["user"] = $user;
}
And as t should, when the user submits the form with correct data, he will be redirected to the ../admin/index.php-page. However, if I take a var_dump($_SESSION), the page tells me this variable is NULL.
What more do I need to do to make sure data is transferred over pages using $_SESSION?
Make sure you call session_start() somewhere everytime you reload a page, or else the server won’t get the session details.