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 4587668
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:48:48+00:00 2026-05-21T21:48:48+00:00

It looks like I still haven’t got the grasp on sessions. Session data will

  • 0

It looks like I still haven’t got the grasp on sessions.
Session data will simply not be accessible for included files or stored when page is reloaded.

I have the following code:

page1.php

<?php
/*
Template Name: Some template
*/

  session_start();  
  $_SESSION['start'] = 'start';
  print_r($_SESSION);

  if(some condition)      
    include('include1.php');
  else
    include('include2.php');
?>

include1.php

<?php
  /* Some comments here */

  $_SESSION['test'] = 'Test text';
  print_r($_SESSION);
?>

include2.php

<?php
  /* Some comments here */

  print_r($_SESSION);
?>

Page1 first includes include1.php where I do some stuff. Then I load page1 including include2.php.

The output result of the print_r() is:

Array ( [start] => start ) // From page 1
Array ( [start] => start [test] => Test text )  // From include 1
Array ( [start] => start ) // From include 2

My question is:
1) Why isn’t [include] outputted in page1.php in the first print_r()after reload?
2) Why isnt’ [include]outputted in include2.php?

I only add session_start() in page 1 since the other two files are included. I’ve also tried adding session_start() in both include files, but that doesn’t work either, since it creates new instances.

UPDATE
My “actuall” include code:

  switch($action) {
    case 'a': include_once('include/include1.php'); break;
    case 'b': include_once('include/include2.php'); break;
    //default:  
  }
  print_r($_SESSION); // <- Here all registered session variables are outputed
  • 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-05-21T21:48:48+00:00Added an answer on May 21, 2026 at 9:48 pm

    The code you displayed is working the way it is supposed to:

    You initialized sessions – session_start()

    You created the first element in the array – start

    On the first include, you added an array element to $_SESSION by adding the key test

    When you output the first include, it includes both start and test

    On the second include, you did not add any array elements to $_SESSION, which is why it outputs only start

    The include code you stated only calls in the first page, or the second page, but not both.

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

Sidebar

Related Questions

Looks like XSD.exe is not delivered as a part of Visual Studio 2010. what
I've got a very large xml data set that is structured like the following:
Looks like this question has been asked thousand times already, but each person's configuration
Looks like while( condition ) { //do stuff } is completely equivalent to for(
Looks like ExpressionTrees compiler should be near with the C# spec in many behaviors,
Looks like there is no Load event for usercontrol on the CF. I'm used
Looks like dynamic memory allocation without garbage collection is a way to disaster. Dangling
Looks like operator new and operator new[] have exactly the same signature: void* operator
Looks like the options are Propel, Doctrine, and ActiveRecord, others?, but I am only
Looks like a dumb question, but I tried the following (where Me is a

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.