Forum Moderators: coopster
Been looking at ways to redirect a user to another page. I've seen the location header php function thingymigig, but, it seems you cant do anything before it otherwise it throws an error in your face.
How do you redirect a user to another page after they have sent you an email or logged in using a form or something.
Do you use a javascript redirect or..do you stick the php script that processes the form inside a webpage, where you want the end result to be displayed like "you have succesfully logged in" for example? So the user doesn't get a blank white page with the message across the top left with no other way of getting back to your site except pressing the back button or re-typing in your website address...
:)
If you use the header('Location: absolute URL'); then PHP sends a 302 header with the location. For HTTP/1.1 a header must be an absolute url (seeing as most browsers are built to deal with our (webmasters) inadequacy's they accept relative url's as well, however this is incorrect from the W3C [w3.org]).
So if you want to be able to have a form that sends information to you then redirect people you have a number of choices.
1) <form action="some_other_page">
On some_other_page do whatever you want with the information then use header('Location: ...'). As there is no HTML on some_other_page you dont need to worry about where the header is placed in the code, as this will be the only thing sent to the browser.
2) redisplay on the same page
if($_POST['submit']) {
// do whatever with the data
header('Location: ...');
}
else {
// display the page
}