saeed_violinist Posted July 10, 2007 Share Posted July 10, 2007 Hi, I designed my site in a way that the template is loaded from a php file that included in every page of my site. Now I want to know if I put SESSION_START() function in this template file so I can access the session variables in every page, when every page is accessed from theme.php a new sesion_start will be generated. So, this session starts in every page , will this cause session variables in last page to be deleted? and If your answer is YES, what you suggest instead of putting session start in main template code. Quote Link to comment https://forums.phpfreaks.com/topic/59225-question-about-session_start-function/ Share on other sites More sharing options...
chocopi Posted July 10, 2007 Share Posted July 10, 2007 your sessions will only be deleted if you use unset() or session_destroy() or $_SESSION['blah'] = array(); // I think So if you use session_start() multiple times it will not delete your previous sessions. Hope that helps ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/59225-question-about-session_start-function/#findComment-294192 Share on other sites More sharing options...
saeed_violinist Posted July 10, 2007 Author Share Posted July 10, 2007 I Think You mean its not important how many session_start called in pages. correct me if I wrong. Thanks friend. Quote Link to comment https://forums.phpfreaks.com/topic/59225-question-about-session_start-function/#findComment-294194 Share on other sites More sharing options...
chocopi Posted July 10, 2007 Share Posted July 10, 2007 yea it does not matter how many times you call a session Quote Link to comment https://forums.phpfreaks.com/topic/59225-question-about-session_start-function/#findComment-294197 Share on other sites More sharing options...
wildteen88 Posted July 10, 2007 Share Posted July 10, 2007 session_start always checks whether there was a valid session id used previously. The session id is normally stored in a cookie. This id is relates to a session file stored on the server. PHP then compares those two to see if the session is still valid, eg the session has not timed out or whether the session file exists. You can call session_start as many times as you like, eg: <?php session_start(); $_SESSION['blah'] = 'hello'; session_start(); The second call to start the session will just get ignored. PHP will not reset any of the session variables unless you have told it to kill the session using either session_destroy or unset. Or whether the session has been timed out or when you delete your cookies on your computer/browser. Quote Link to comment https://forums.phpfreaks.com/topic/59225-question-about-session_start-function/#findComment-294537 Share on other sites More sharing options...
obyno Posted July 10, 2007 Share Posted July 10, 2007 I know what you mean. A code snippet I have always used to not worry about sessions this way is to do this: if(session_id() == "") { session_start(); } before the start of any page where there is a need for session info. That way I knda have both ends of the bargain neatly covered. Quote Link to comment https://forums.phpfreaks.com/topic/59225-question-about-session_start-function/#findComment-294546 Share on other sites More sharing options...
saeed_violinist Posted July 10, 2007 Author Share Posted July 10, 2007 thanks for your advises friends. Quote Link to comment https://forums.phpfreaks.com/topic/59225-question-about-session_start-function/#findComment-294574 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.