Jump to content

Recommended Posts

I cannot use a header redirect anymore because I'm echo'ing out in the header.php file for the navigation, which will echo out a profile and settings button ONLY if the user is logged in, it's basically a simple if statement with session variables.

 

Now when the user goes to the login page and has successfully logged in I'd like to redirect the user to the main page, but of course this won't work since I have already an echo in the header.php file for the navigation.

 

So my question is, is there a workaround or alternate redirect for this case?

Link to comment
https://forums.phpfreaks.com/topic/231995-alternative-to-header-redirect/
Share on other sites

Why are you sending content if all you are going to do is redirect? It makes no sense to do so.

What do you mean with this? Can you further elaborate? Which content are you talking about?

 

Put the login above the echoed statement to avoid the issue.  The only other way would be to use a meta refresh, but they would then be loading multiple pages, rather than one.

 

That would mean I'd have to put the login form into the header.php which I include into each and every web document. Is this common practice, are other websites doing it this way as well? (Sorry for this newbie question).

You don't have to put the login form in the header, just use a get variable and inside the if statement for that, have it set the session or cookie and use header refresh to send you to the login completion page.  The login form would go on the login page, which should not be in the header.  On my site, there is a login form in the header, but it's at the bottom of it, so all issues are avoided with redirections and header info.

Why are you sending content if all you are going to do is redirect? It makes no sense to do so.

What do you mean with this? Can you further elaborate? Which content are you talking about?

 

"I cannot use a header redirect anymore because I'm echo'ing out in the header.php file for the navigation, which will echo out a profile and settings button ONLY if the user is logged in, it's basically a simple if statement with session variables."

 

That content. Scripts that process user input should be in files that produce NO OUTPUT, this way, when they are done you can easily redirect your user to where they need to be. There is no point sending ANY output to the browser if all you are going to do is redirect the user somewhere else.

You don't have to put the login form in the header, just use a get variable and inside the if statement for that, have it set the session or cookie and use header refresh to send you to the login completion page.  The login form would go on the login page, which should not be in the header.  On my site, there is a login form in the header, but it's at the bottom of it, so all issues are avoided with redirections and header info.

 

What you're saying is, the script itself should be in the header, but the form on the separate login page.

 

 

 

"I cannot use a header redirect anymore because I'm echo'ing out in the header.php file for the navigation, which will echo out a profile and settings button ONLY if the user is logged in, it's basically a simple if statement with session variables."

 

That content. Scripts that process user input should be in files that produce NO OUTPUT, this way, when they are done you can easily redirect your user to where they need to be. There is no point sending ANY output to the browser if all you are going to do is redirect the user somewhere else.

 

In my case there's a point which is an aesthetics reason. The user lands on the main page, with some overview information what the website provides, in the navigation is the signup/signin link, if the use now clicks on it he'll be led to a page with two forms, both separated by a 1 px line, on one side the registration form and on the other side the login form. If I now would present this page without any header, no logo, no navigation, not any of that, then that would decrease the user friendliness of the website and would make it look less aesthetically pleasing.

 

Another solution would be I could modify the header and create a second header.php file without the if statement and session variables just for the login page, that way there would be no echo and I could simply re-direct, but putting the login SCRIPT above the navigation and having the FORM on the login page seems to be a better solution, I like that more than having two different header documents.

 

Thanks for all the suggestions.

You're missing the point thorpe is making.  Your form DISPLAY script needn't be the same file as your form PROCESSING script.  The processing script doesn't need to display any output and would be able to redirect the user.  The user would simply see your forms, then be taken to where ever you want them to go after form submission.

Ok that makes sense, so basically everybody was saying the same just worded differently lol.

 

What I did was I have four files now:

 

login_script.php

register_script.php

login_form.php

register_form.php

 

 

I include the script files into the header.php

and the form files into the page where people can either sign in or sign up.

 

I think this is a proper way of doing it and it works so far.

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.