Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/272088-redirection-problem/
Share on other sites

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:).

Link to comment
https://forums.phpfreaks.com/topic/272088-redirection-problem/#findComment-1399799
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/272088-redirection-problem/#findComment-1399831
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.