Home > Tips & Tricks > PHP Redirect to Another Page

PHP Redirect to Another Page

Do you want to redirect your page to another page in PHP? Then I will show you how you can make redirection from current page to another page in php.

To redirect to another page in php, you can use the header() function to send the raw HTTP header and redirect to your page. Let’s have a look at in details with example.

Using header()

The header() function is built-in function and it used to send a raw HTTP header but make sure header() call before sent the actual output.


header(string $header, bool $replace = true, int $response_code = 0)


$header: used to hold the header string and it can be two types of string, first one is start the string with “HTTP/” and second is “Location:”.

$replcae: used to indicates whether the header should replace a previous similar header, or add a second header of the same type. It is boolean and optional parameter.

$response_code: Sets the HTTP response code to the given value. This option only has an impact if the header isn’t blank.

header() example:

Note: Remember that header() must be called before sending any output, either by normal HTML tags, blank lines in a file, or from PHP. OR use the die() or exit() function after the header() function.

Being Tricky 😉

Photo of author

About Aman Mehra

Hey there! I'm Aman Mehra, a full-stack developer with over six years of hands-on experience in the industry. I've dedicated myself to mastering the ins and outs of PHP, WordPress, ReactJS, NodeJS, and AWS, so you can trust me to handle your web development needs with expertise and finesse. In 2021, I decided to share my knowledge and insights with the world by starting this blog. It's been an incredible journey so far, and I've had the opportunity to learn and grow alongside my readers. Whether you're a seasoned developer or just dipping your toes into the world of web development, I'm here to provide valuable content and solutions to help you succeed. So, stick around, explore the blog, and feel free to reach out if you have any questions or suggestions. Together, let's navigate the exciting world of web development!

Leave a Comment