Showing posts with label Redirect. Show all posts
Showing posts with label Redirect. Show all posts

Wednesday 1 August 2012

PHP Redirect To Another URL


How do I redirect with PHP script?

Using headers() method, you can easily transferred to the new page without having to click a link to continue. This is also useful for search engines. Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

PHP Redirect Script

You can easily redirect using following code:
 
<?php
/* Redirect browser */
header("Location: http://www.yoursitename.com/");
/* Make sure that code below does not get executed when we redirect. */
exit;
?>