Jump to content

Session and Includes


doubledee

Recommended Posts

If one file includes another, do I need to start a session in each, or does the included file "inherit" the session?

 

script_1.php

// Initialize Session.
session_start();

// Require Function
require_once('script_2.php');

 

 

script_2.php

// Initialize Session.
session_start();		DO I NEED THIS HERE?????????

if ($_SESSION['loggedIn'] == TRUE){
	do something
}

 

 

Debbie

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/258618-session-and-includes/
Share on other sites

It "inherits". The reality is that PHP keeps executing from where it left off - nothing changes, nothing resets, nothing goes away. It's basically the same as copy/pasting the code from script_2 into script_1.

 

So if I start a session in the "including" script, then the "included" script is just plopped into the "including" script and it is like it is all one large master file playing together nicely, right?

 

 

Debbie

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.