Dirty-Rockstar Posted August 16, 2007 Share Posted August 16, 2007 user logs in, passes thru auth.php..if that passes $_Session[usersession] is now true. on include.php i have session_start(); include.php is on all pages. do i have to have session_start(); on any other pages to keep session active? or will include.php do it for me hope i worded that right Quote Link to comment https://forums.phpfreaks.com/topic/65285-solved-session-start-on-an-include-page/ Share on other sites More sharing options...
piznac Posted August 16, 2007 Share Posted August 16, 2007 I just found this as a comment in the manual: TAGS: session_start headers output errors include_once require_once php tag new line Errors with output headers related to *session_start()* being called inside include files. If you are starting your session inside an include file you must be aware of the presence of undesired characters after php end tag. Let's take an example: > page.php <?php include_once 'i_have_php_end_tag.inc.php'; include_once 'init_session.inc.php'; echo "Damn! Why I'm having these output header errors?"; ?> > i_have_php_end_tag.inc.php <?php $_JUST_A_GLOBAL_VAR = 'Yes, a global var, indeed'; ?> > init_session.inc.php <?php session_start(); $_SESSION['blabla'] = 123; ?> With all this stuff we will get an error, something like: "... Cannot send session cache limiter - headers already sent (output started at ...", right? To solve this problem we have to ignore all output sent by include files. To ensure that we need to use the couple of functions: *ob_start()* and *ob_end_clean()* to suppress the output. So, all we have to do is changing the *page.php* to this: <?php ob_start(); include_once 'i_have_php_end_tag.inc.php'; include_once 'init_session.inc.php'; ob_end_clean(); echo "Woo hoo! All right! Die you undesired outputs!!!"; ?> **if Im not allowed to post stuff like this admins please delete and let me know Quote Link to comment https://forums.phpfreaks.com/topic/65285-solved-session-start-on-an-include-page/#findComment-326020 Share on other sites More sharing options...
nathanmaxsonadil Posted August 16, 2007 Share Posted August 16, 2007 if your include is on the very top (except your start tag <?php) and your session start is on the very top (except your start tag <?php) of your include page it should work Quote Link to comment https://forums.phpfreaks.com/topic/65285-solved-session-start-on-an-include-page/#findComment-326024 Share on other sites More sharing options...
Dirty-Rockstar Posted August 16, 2007 Author Share Posted August 16, 2007 if your include is on the very top (except your start tag <?php) and your session start is on the very top (except your start tag <?php) of your include page it should work yep that is exactly how it is, i always put my included pages at the top of each page before i code (after the start tags of course) and on include.php the first thing is the session thanks Quote Link to comment https://forums.phpfreaks.com/topic/65285-solved-session-start-on-an-include-page/#findComment-326028 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.