brady123 Posted September 6, 2010 Share Posted September 6, 2010 I have an include file that is included in every page of my website. I'm using sessions and trying to streamline code. The very first line of any page is my include file, and the very first thing in that file is: <?php session_start(); ?> The page doesn't register that a session was started. Do I have to have session_start() on every single page? Or is there a way to have it in my include file so it is automatically on every page for me? Thank you! Quote Link to comment Share on other sites More sharing options...
Hypnos Posted September 7, 2010 Share Posted September 7, 2010 Do I have to have session_start() on every single page? Or is there a way to have it in my include file so it is automatically on every page for me? session_start() has to be ran on every page. How you do that is up to you. It can be on an included script or the script itself. Most people will put it in an file that is included at the start of every page. Quote Link to comment Share on other sites More sharing options...
brady123 Posted September 7, 2010 Author Share Posted September 7, 2010 I'm trying that, but it's not working. For example, I have this at the beginning, the very first thing, of every page: <?php include ("/headerinfo.php"); ?> The page continues from there. In that 'headerinfo' include file, I have on the very first line: <?php session_start(); ?> I imagine that's what I need to do to have sessions started on every page, but for some reason, pages aren't recognizing it. Any thoughts/tips? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 7, 2010 Share Posted September 7, 2010 Are you sure the include() is actually working? Check you error logs for errors regarding the include function, and try echoing something directly from the included file. My guess is that the path is probably wrong. Quote Link to comment Share on other sites More sharing options...
pengu Posted September 7, 2010 Share Posted September 7, 2010 I don't think it will work, but I never use brackets with include.. <?PHP include 'myfile.php'; ?> All you need Quote Link to comment Share on other sites More sharing options...
Rifts Posted September 7, 2010 Share Posted September 7, 2010 I'm trying that, but it's not working. For example, I have this at the beginning, the very first thing, of every page: <?php include ("/headerinfo.php"); ?> The page continues from there. In that 'headerinfo' include file, I have on the very first line: <?php session_start(); ?> I imagine that's what I need to do to have sessions started on every page, but for some reason, pages aren't recognizing it. Any thoughts/tips? dont use <?php include ("/headerinfo.php"); ?> it should be <?php include ("headerinfo.php"); ?> Quote Link to comment 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.