Cannot redirect user

At first I could not use,pug,am used to html cause I only know how to deal with files witch contains path.Basically I want to redirect a successful register user to a profile file. Now each time I register message >cannot get profile.
I check the console log message >cannot set header after the message have been sent to client. This very error I tried research but I don’t get it.please how can I redirect successful.

This was probably hard to understand if you don’t have a sense of what things are sent to the client as headers and what things are sent as the “message.” Important to this question is that a redirection is sent as a header. On the other hand, any HTML content is sent as the “message.”

That said, the problem as stated in the error message is a sometimes inconvenient property of HTTP. It’s a language with its own rules about what goes where in each response. Headers go before the body.

I haven’t looked at the code you shared, but there are a few general ways to do deal with this:

  1. If you can rearrange code so that it does the redirection before echoing out the body, that would be exactly what the error description is calling for. You probably could have figured this out yourself given that extra information about what exactly were the header and message that were coming out the wrong way around.
  2. Don’t send a message at all. Can’t get two things in the wrong order if there isn’t a second thing, after all. This not too crazy really, because if this is to be a redirection, people wouldn’t have time to read through any page that you send anyway.
  3. Buffer up the message in memory instead of sending it right away. Using an output buffer is a pretty big hammer, but sometimes there’s no other way.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.