To redirect to another URL or web page in PHP, you can use the header
function with the Location
header.
Here is an example of how to use the header
function to redirect to another URL:
<?php header('Location: http://www.example.com/'); exit;
This will redirect the client to the specified URL. It's important to note that the header
function must be called before any output is sent to the client. This means that you should place the header
function at the top of your PHP script, before any HTML or other output.
You can also use the header
function to redirect to another page on the same website. For example:
<?php header('Location: /another-page.php'); exit;
This will redirect the client to the another-page.php
page on the same website.
It's important to note that the header
function is not the only way to redirect to another URL or web page in PHP. You can also use JavaScript or an HTML meta
tag to achieve the same result. Consult the PHP documentation and online resources for more information.