Jump to content
MakeWebGames

Recommended Posts

Posted

Can I include a file when the session is set then another if its not set?

e.g.

 

if session = 1 {

include file

}
else
{

include  different file

}

 

I know it's not correct code but I'm feeling lazy... I hope you guys can get the idea of what I'm on about....

Posted
if(isset($_SESSION['seshid']))
{
//include file
}
else
{
//include other file
}

 

Replace seshid with your session name

Posted

Multiple way's to accomplish this, it depends on what you are checking for.

 

// Check if user has a session id of some sort
if(array_key_exists('session_id', $_SESSION))	{

// Session active
include_once('path/here.php');

}	else	{

// No session Active
include_once('path/here.php');

}



// Check if session is active
$session_type = session_status();
if($session_type == PHP_SESSION_DISABLED)	{

// No session active, sessions disabled (IE: no session_start() called)
include_once('path/here.php');

}	else if($session_type == PHP_SESSION_NONE)	{

// Sessions are enabled (IE: called to session_start()), but no sessions active (Have no session id)
include_once('path/here.php');

}	else if($session_type == PHP_SESSION_ACTIVE)	{

// Sessions are enabled (IE: called to session_start()), and there is currently an active session
include_once('path/here.php');

}



// Using a pre defined variable
if(defined('SID'))	{

// Session active
include_once('path/here.php');

}	else	{

// Session not active
include_once('path/here.php');

}

 

A simple google search for "php how to detect if session is active", can yield many results.

Posted
Thanks Angel

I'm planning on making a small skeleton framework that can be used for any website.

Good luck with that, the competition is fierce for frameworks.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...