| Viewed 99 times

PHP how to redirect to another page


PHP how to redirect to another page

PHP
1 Answer
Mohammad Qandeel
Answered
8

There are many ways to redirect to another page in PHP

One of the most famous ways is Header Function

To make a simple redirect using header() function look to this example 

<?php 
    header("Location: https://www.qandeelacademy.com"); 
    exit(); 
?> 

save the code in .php file and open it will redirect to https://www.qandeelacademy.com

you can change the target to any URL or File like header("Location: /post/index.php"); 

using exit() function is important to prevent the script from executing after redirect 

note: HTTP headers must be sent before any type of content