Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8098583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:07:05+00:00 2026-06-05T22:07:05+00:00

My session don’t seem to be saved. I have a log in page that

  • 0

My session don’t seem to be saved. I have a log in page that saves the users id as a session. But when I leave the page and click on another page the sessions are not saved.

Here are my code. I have a main page called index.php that look like this:

<?php
if(!isset($_SESSION)){
       session_start();
}
?>

<!DOCTYPE html> <HTML> <HEAD> </HEAD> <BODY>

<?php
$page_content = 'startpage.php';

if (isset($_GET['link']) && !empty($_GET['link']) ) {
    $page_content = $_GET['link'];
}

include "$page_content";
include 'menu.php'; 
include 'footer.php';  
?>

To login I use this page called admin.php. Within this page I have loggin code that works fine.
If the user has written right username and password then this happens:

$_SESSION['user_id'] = $user_id;            
print_r($_SESSION);

The code above shows the current sessions variables. But as soon one click on another page the variables are left empty.

At the bottom of index.php are the footer.php page included, and it looks like this:

<?php
if(!isset($_SESSION['user_id']) ){        
    echo "The sessions are not initiated. ";        
} 

if (empty ($_SESSION['user_id']) ) {
    echo "The sessions are empty. ";
}

echo "<a href='index.php?link=admin.php'>Administration</a>";
?>

In this footer I have put two if questions to check the sessions.
After I have succeded to logg in and clicked on an another page the if questions detect that my session are empty and not initiated.

How should I get the sessions to work?

Perhaps I should add that I use a rent database that use MySql.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T22:07:06+00:00Added an answer on June 5, 2026 at 10:07 pm

    Before you can use $_SESSION you should always start it with:

    session_start()
    

    Also, session_start() must always be called before you output anything on the page, otherwise it will not work properly

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a magic getter/setter class for my session variables, but I don't
I know that I can retrieve session by using item.fields.name but what if I
Since I don't have in depth knowledge of spring session scope implementation. Can anyone
I can use the Session fine, but I don't know how to control the
I have a number of AJAX calls that still partially work if the SESSION
I have a rails engine code. But Rails::Engine don't have config.session_store variable. module Admin
I can set session variables and use them on another page. However when i
Don't get me wrong, I want them to get saved. But I always thought
I'm running PHP on Windows/IIS. My session variables don't seem to be preserved from
I am in a MySQL terminal session but I don't know what server I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.