PHP redirect to another page

To redirect to another page in PHP, you can use the header() function. The header() function sends a HTTP header to the browser, which tells the browser to redirect to the specified URL. The following code shows how to use the header() function to redirect to another page:


<?php

// Redirect to the homepage

header("Location: http://www.bospp.com");

?>


The header() function can also be used to redirect to a page on the same server. The following code shows how to redirect to a page on the same server:


<?php

// Redirect to the contact page

header("Location: contact.php");

?>


The header() function can also be used to redirect to a page that is not on the same server. However, it is important to note that some browsers may not allow you to redirect to a page that is not on the same server.


The header() function must be called before any output is sent to the browser. If any output has already been sent to the browser, the header() function will not work.


No comments:

Post a Comment