How to make a redirect in PHP?

Spread the love

Sometimes, we want to make a redirect in PHP.

In this article, we’ll look at how to make a redirect in PHP.

How to make a redirect in PHP?

To make a redirect in PHP, we can use the header function.

For instance, we write

header('Location: '.$newURL);

to call header with 'Location: '.$newURL to redirect to the URL stored in $newUrl.

This will send the Location response header with the new location.

The 302 status code will be used for the redirect.

Conclusion

To make a redirect in PHP, we can use the header function.

Leave a Reply

Your email address will not be published. Required fields are marked *