Redirect to another web page using PHP

Contributor Icon Contributed by qmchenry Date Icon June 9, 2004  
Tag Icon Tagged: PHP programming

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.

Previous recipe | Next recipe |
 
  • Robin Pahwa
    check your website it has no php script
  • Thanks Robin! We recently migrated to WordPress and some of our code blocks didn't quite make it.
  • is there any alternative of this header , so that next page is redirected without any event(not by hyperlin)
  • 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?
  • hii is i possible to send variables using this
  • vinu
    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
    Hi thanks for this article.This is very useful and easily clear my doubts.Thank you..........
  • I also got "Headers already sent" problem
  • asdas
    chutad hai tu
  • thanks and i solved my problems
  • i want to redirect my PHP page using variable instead of fixed url
    Thanks so much
  • Thanks for the php redirect page code!
blog comments powered by Disqus