Redirection is an integral part of modern website. If something happens on your website like a user submitted a comment or logged in, he should be redirected to thank you page or user profile page respectively.
PHP provides a simple and clean way to redirect your visitors to another page that can be either relative or can be cross domain.
PHP code with HTML to redirect to another page:
This is a simple PHP script, so we put a form that inputs a name and comment. In the PHP script we check if the server request method is post because we don’t want this code to execute if user hasn’t submitted the form through POST method, which is only possible if he submit the form.
Next, we store the values received in $comment and $name variables. Then we check if they are not empty, that is they have some value, then we redirect the visitor to thankyou.html page.
So this is how you redirect to another page using header() function in PHP.
The thank you page contains a simple thank you message in html file, since it is just for display.
need an explanation for this answer? contact us directly to get an explanation for this answer