After a successful login, I save the session variable.
When the user navigates to different pages in the application, the session is gone, although I did not explicitly destroy the session. How to fix it?
Here is the page where the session disappears.
<?php include 'core/init.php'; include 'core/sendmessage.php'; $user_info = $_SESSION['user_id']; $getUser = mysql_query("SELECT * FROM users WHERE user_id = ".$uid); $user_info = array(); while($currentRow = mysql_fetch_array($getUser)){ $user_info['firstname'] = $currentRow['first_name']; $user_info['lastname'] = $currentRow['last_name']; $user_info['username'] = $currentRow['username']; } ?>
Inside core/init.php I have a method to start a session.
<?php session_start(); require 'database/connect.php'; require 'functions/users.php'; require 'functions/general.php'; if (logged_in() === true) { $user_data = user_data($_SESSION['user_id'],'first_name','last_name','username'); } $errors = array(); ?>
source share