Ben Nash Posted July 11, 2013 Posted July 11, 2013 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.... Quote
Guest Posted July 11, 2013 Posted July 11, 2013 if(isset($_SESSION['seshid'])) { //include file } else { //include other file } Replace seshid with your session name Quote
Ben Nash Posted July 11, 2013 Author Posted July 11, 2013 Thanks Angel I'm planning on making a small skeleton framework that can be used for any website. Quote
HauntedDawg Posted July 11, 2013 Posted July 11, 2013 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. Quote
Guest Posted July 11, 2013 Posted July 11, 2013 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.