Upon successful login, I’m saving the session variable.
When the user goes to different pages in the app, the session is gone even though I didn’t explicitly destroy the session. How do i fix this?
Here is a page where the session appears to disappear.
<?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'];
}
?>
Within core/init.php I have the session start method.
<?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();
?>
Add
session_start()on the beginning of each page (after your<?phptag).In your case: