How Do I Make a Redirect in Php?

Is it possible to redirect a user to a different page through the use of PHP?

Say the user goes to and I want to redirect them to , how would I do so without the use of a meta refresh? Is it possible?

This could even protect my pages from unauthorized users.

6

33 Answers

Summary of existing answers plus my own two cents:

1. Basic answer

You can use the header() function to send a new HTTP header, but this must be sent to the browser before any HTML or text (so before the <!DOCTYPE ...> declaration, for example).

header('Location: '.$newURL);
Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.