chaseman Posted March 28, 2011 Share Posted March 28, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/231995-alternative-to-header-redirect/ Share on other sites More sharing options...
trq Posted March 28, 2011 Share Posted March 28, 2011 Why are you sending content if all you are going to do is redirect? It makes no sense to do so. Quote Link to comment https://forums.phpfreaks.com/topic/231995-alternative-to-header-redirect/#findComment-1193469 Share on other sites More sharing options...
codefossa Posted March 28, 2011 Share Posted March 28, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/231995-alternative-to-header-redirect/#findComment-1193470 Share on other sites More sharing options...
chaseman Posted March 28, 2011 Author Share Posted March 28, 2011 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). Quote Link to comment https://forums.phpfreaks.com/topic/231995-alternative-to-header-redirect/#findComment-1193473 Share on other sites More sharing options...
codefossa Posted March 28, 2011 Share Posted March 28, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/231995-alternative-to-header-redirect/#findComment-1193478 Share on other sites More sharing options...
trq Posted March 28, 2011 Share Posted March 28, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/231995-alternative-to-header-redirect/#findComment-1193484 Share on other sites More sharing options...
chaseman Posted March 29, 2011 Author Share Posted March 29, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/231995-alternative-to-header-redirect/#findComment-1193500 Share on other sites More sharing options...
KevinM1 Posted March 29, 2011 Share Posted March 29, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/231995-alternative-to-header-redirect/#findComment-1193521 Share on other sites More sharing options...
chaseman Posted March 29, 2011 Author Share Posted March 29, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/231995-alternative-to-header-redirect/#findComment-1193638 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.