Code to redirect after successful submission of form

By annehawkins on Aug 24, 2013

If you have a form which ob being filled, you would like the user to be redirected to another page.
In these cases if you try to post to $_SERVER['PHP_SELF'], this will not work.

The only way to handle this is to use the header() function if no other text/string data has been output by the web server to the users browser.

You'll need to put the logic for the redirect at the top of your script before anything else(Replace your redirection URL.):

The reason for this is that when a browser receives information from the web server it receives an HTTP header (which the header() function outputs the redirect to), and then outputs the body of the HTTP response after the HTTP header. If your script is echoing anything before the header command, you'll continue to receive error saying that the header information cannot be modified.


// Process form

// If processing was successful, redirect

// Replace your redirection URL here



Sign in to comment.
Lucas Lks   -  Apr 17, 2016

Thanks man. Helped me a lot. =)

Noutrious   -  Aug 27, 2013

Not sure if this in any way is worth submitting

Hawkee   -  Aug 24, 2013

Please remove the link drop.

annehawkins  -  Aug 24, 2013


Hawkee  -  Aug 27, 2013

Thank you, can you also remove it from your code example.

Sign in to comment

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.