Redirect to another web page using PHP
Redirection from one web page to another is a handy tool. This recipe describes the syntax that causes the client to redirect to another URL.
The following php script redirects the user to /index.php within the same site:
<? header('Location: /index.php'); ?>
The redirection target can be any suitable URL as could be used in the href parameter of an address tag (such as http://www.tech-recipes.com/index.php). The header function sends raw header data to the client web browser and in this case sends a 302 status code which instructs the browser to redirect to the given location.









Robin Pahwa said on October 15, 2008
check your website it has no php script
Quinn McHenry said on October 15, 2008
Thanks Robin! We recently migrated to WordPress and some of our code blocks didn’t quite make it.
saurabh said on November 13, 2008
is there any alternative of this header , so that next page is redirected without any event(not by hyperlin)
linu said on December 9, 2008
hii is i possible to send variables using this
vinu said on January 14, 2009
hi thanks for this article.
but my problem is that header() is used for redirecting once and i want to redirct page with parameter no. of times what the solution for this?
Malar said on March 12, 2009
Hi thanks for this article.This is very useful and easily clear my doubts.Thank you……….
bassline77 said on March 20, 2009
Yeah, I’ve got the some problem, when i redirect my page this way, it gives me a “headers already sent” error. Is there an alternative?
Anup pokhrel said on April 19, 2009
I also got “Headers already sent” problem
asdas said on May 30, 2009
chutad hai tu
shubham gupta said on November 7, 2009
thanks and i solved my problems
Flight said on November 12, 2009
i want to redirect my PHP page using variable instead of fixed url
Thanks so much
Dave said on November 24, 2009
Thanks for the php redirect page code!
Anonymous said on March 24, 2010
Thanks for sharing
Form builder said on May 3, 2010
I see there are so many ways for redirect
Pratik Dangol said on May 25, 2010
can i get code for data inserting and displaying and recently update the chandes. like facebook commet in wall, while we click publish it will insert data and display the latest updated data of database.
Jackie said on June 1, 2010
just add the url like a get variable and use $_GET to retrieve it.
Adnan said on August 31, 2010
In PHP tag, we should use the following java script
echo “location.href=’abc.php’;”;
Cleverlearncebu said on October 7, 2010
This is 302, how about 301 redirect in PHP? some info please? :)
Info said on October 9, 2010
thanks abunch
Himay said on October 9, 2010
ok thanks, still having problems getting it to work…
bosna said on December 20, 2010
great man
bosna said on December 20, 2010
This is the easiest way i guess.. No header problem at all.. keep up the good work..
Shoaib said on December 27, 2010
java script with php waow jst working good short
Gunn 'em down said on December 28, 2010
what if javascript is disabled in a browser
chintoo said on January 7, 2011
thanks mate… i got my code working with it….
Gauri said on February 18, 2011
hey this solution is awesome and works without header errors… Thanks a lot
My Offhegoes said on March 31, 2011
Your solution working like a charm.. solve my problem..
Lifemate 2 said on April 4, 2011
you know what! I already knew how to redirect but by looking at ur code … that reminds me to the url which I had entered ! the only thing was the wrong page … anyways thanks…
Sendilrrk said on April 26, 2011
Please add ob_start() to your connection file.
the raging homosexual said on July 1, 2011
this is disgraceful trolololololololol
raging homo sexual nose said on July 1, 2011
looooooooooooooooooooooooooooooooooooooool spam
Ty said on August 27, 2011
Hi,
What “address” do you put in the initial webpage html to call the php file?
The php file runs and redirects when I type it into the address of IE, but I can’t seem to call the file from the initial page!
Stephen said on September 19, 2011
hi
I need to redirect my old page to a new page, the page is made in PHP. so please tell me what is the code to redirect from one page to another page.
witek said on December 1, 2011
Location must point to absolute URL with full hostname!
maged said on December 20, 2011
thanks man you are great