HomeWeb application programmingPHP programmingRedirect to another web page using PHP

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.

Quinn McHenry
Quinn McHenry
Quinn was one of the original co-founders of Tech-Recipes. He is currently crafting iOS applications as a senior developer at Small Planet Digital in Brooklyn, New York.
RELATED ARTICLES

42 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

Recent Comments

Cleveland Furia on How to Clear Google Activity
Sid Wohlfarth on How to Clear Google Activity
Riley Magsayo on How to Clear Google Activity
สมัครรับเครดิตฟรี ทันที on How to improve Remote Desktop Protocol Performance
Neal Wangstad on How to Clear Google Activity
Slavcho Andov on How to install Ubuntu
Slavcho Andov on How to fix bad sectors
Sheraz Ali on How to Backup Android