shrive22 Posted June 25, 2009 Share Posted June 25, 2009 I want to name my session something other than the default but when I uncomment the first line my page restriction code no longer works. The following code is from my session include file that is included on every restricted page: <?php //session_name("docduedate_session"); session_start(); function logged_in() { return isset($_SESSION['emp_no']); } function confirm_logged_in() { if(!logged_in()) { redirect_to("index.php"); } } ?> Any help would be appreciated. thanks Quote Link to comment https://forums.phpfreaks.com/topic/163670-solved-custom-session-name/ Share on other sites More sharing options...
Rayhan Muktader Posted June 25, 2009 Share Posted June 25, 2009 The session name is reset to the default value stored in session.name at request startup time. Thus, you need to call session_name() for every request (and before session_start() or session_register() are called). Quote Link to comment https://forums.phpfreaks.com/topic/163670-solved-custom-session-name/#findComment-863564 Share on other sites More sharing options...
shrive22 Posted June 25, 2009 Author Share Posted June 25, 2009 Isn't that what I am doing? If I uncomment the first line the first thing php does in every restricted page is session_name(), secondly php does session_start(). Quote Link to comment https://forums.phpfreaks.com/topic/163670-solved-custom-session-name/#findComment-863566 Share on other sites More sharing options...
PFMaBiSmAd Posted June 25, 2009 Share Posted June 25, 2009 What about the page where you log in? Quote Link to comment https://forums.phpfreaks.com/topic/163670-solved-custom-session-name/#findComment-863569 Share on other sites More sharing options...
shrive22 Posted June 25, 2009 Author Share Posted June 25, 2009 just check to be sure, it also starts with my session include file and thus the session_name() Quote Link to comment https://forums.phpfreaks.com/topic/163670-solved-custom-session-name/#findComment-863575 Share on other sites More sharing options...
Skepsis Posted June 25, 2009 Share Posted June 25, 2009 Couldn't you just store the session name inside a variable. $session_name = session_name("docduedate_session"); Then when you use a function, you just add the variable to the globals. function logged_in() { global $session_name; return isset($_SESSION['emp_no']); } Quote Link to comment https://forums.phpfreaks.com/topic/163670-solved-custom-session-name/#findComment-863580 Share on other sites More sharing options...
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.