mds1256 Posted April 22, 2012 Share Posted April 22, 2012 I will explain my scenario and if anyone can give me an idea on how to accomplish it that would be great. I have included a header file which contains my html meta tags and banner. I then have a footer file which contains my end html tags and my site's footer. Then I have the individual pages e.g. contact us, home, etc and I include the header and footer file within these documents so I only need to edit the header / footer in one location. My dilemma is that on one of my pages (myprofile page) I want it to check if I have logged in first, if not then re-direct to the login page. But when checking for my session variable (isLoggedIn) which is turned from false to true when user has successfully logged in and then using header location to redirect to a login page if it is not equal to true it returns that headers are already sent (which I know as the html from my header has already been loaded). Now the first thing I thought about was to check this in the header but when browsing the home page I dont want users having to login before viewing the home page or contact us page. Any idea on how I can achieve this? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/261435-header-location-redirect-after-html-has-began-outputting/ Share on other sites More sharing options...
wigwambam Posted April 22, 2012 Share Posted April 22, 2012 Add the code to the myprofile.php page, just before the include header. Quote Link to comment https://forums.phpfreaks.com/topic/261435-header-location-redirect-after-html-has-began-outputting/#findComment-1339653 Share on other sites More sharing options...
mds1256 Posted April 22, 2012 Author Share Posted April 22, 2012 Add the code to the myprofile.php page, just before the include header. Good idea, never even thought of that! Although I start the session in the header file, is it ok to call session start twice? E.g. Session start If session-isloggedin = false header redirect to login page End if Include header (which also includes session start) From the pseudo code above is that ok or is there a better way! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/261435-header-location-redirect-after-html-has-began-outputting/#findComment-1339664 Share on other sites More sharing options...
mds1256 Posted April 23, 2012 Author Share Posted April 23, 2012 I have now sorted this by reorganising my code. Thanks for the response above it helped a lot Quote Link to comment https://forums.phpfreaks.com/topic/261435-header-location-redirect-after-html-has-began-outputting/#findComment-1339714 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.