Jump to content

header location redirect after html has began outputting


mds1256

Recommended Posts

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

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.