Classico Posted December 17, 2012 Share Posted December 17, 2012 I've ran into this problem many times, and I'm sure others have too. I'm trying to redirect users to the main page after login/doing other stuff on the website. But every time I login just to test it, I keep getting an error something about the header (can't remember the full error, haven't tested it in a while). I'm using the PHP's way of redirecting: header("Location:index.php"); I managed to find a work around, by outputting a link if they've logged in and when they click on the link, it takes them to the selected page. But I don't want that. I want it so it redirects automatically. I do have error reporting on. Is there a way to get this working, without the error? I can post my login code if needed. Quote Link to comment https://forums.phpfreaks.com/topic/272088-redirection-problem/ Share on other sites More sharing options...
Muddy_Funster Posted December 17, 2012 Share Posted December 17, 2012 did you read the sticky on header errors at all before posting this? no, clearly not. did you search for other posts relating to header errors before you posted this? no, clearly not. So, lets answer this question yet again... Your issue is that you are trying to manipulate the header content after it has been sent to the browser. That's just not going to happen, so you get an error. Either process the header() value without printing anything to page before hand, ot use a JS window.location="..." on successfull login instead of the PHP header(Location:). Quote Link to comment https://forums.phpfreaks.com/topic/272088-redirection-problem/#findComment-1399799 Share on other sites More sharing options...
PFMaBiSmAd Posted December 17, 2012 Share Posted December 17, 2012 Is there a way to get this working Of course, start by really reading all the parts of the error message. It tells you where you are sending the output at on your page that is preventing the header from working. Then you identify what that output is and prevent it, usually by rearranging your logic on your page so that you determine if you are going to redirect or stay on the page first, then only send output to the browser if you are going to stay on that page. Quote Link to comment https://forums.phpfreaks.com/topic/272088-redirection-problem/#findComment-1399831 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.