The PHP 5 header function is used to Send a raw Http header.
If it Content begin with the “Location:” keyword it Result in a 302 Redirection.
But the Redirection Work only if the Header hasn’t already be Sent, so the function has to be executed before production of any other Output.
So to Redirect somewhere from inside your Scripts:
-
The header function need to Result Placed at the Top of the Page or Before any HTML Tag/Content
-
Execute the header function with an Argument Starting by “Location:”
header('Location: http://redirect/To/This/URL')
When Not Sure if Headers are already been Sent you need to Couple it with an header_sent() Check like this:
if (!header_sent()) {
header('Location: http://redirect/To/This/URL');
} else {
/necho "Cannot redirect, for now please click this
"href="http://redirect/To/This/URL"" .
">link instead";
}