Redirect to another PHP page. Code example open

Redirect to another PHP page. Code example

Approved. Code works!
This is exactly the working code that is verified by the moderator or site administrators

To redirect to another PHP page, you can use the header function in PHP. The header function allows you to send HTTP headers, including the Location header, which is used for redirection.

Here’s an example of redirecting to another PHP page:

header('Location:profile.php');
exit;

In this example, the header function is used to set the Location header to the desired PHP page ( profile.php ). The exit statement is then used to stop further execution of the current script.

Make sure that the header function is called before any output is sent to the browser, as headers must be sent before any actual content. Also, note that after the header function is called, you should use exit or die to stop the script execution, as the redirection will not take effect if the script continues to execute.

When to use

  • After successful processing of the form: If you process the data sent by the user through the form and want to redirect the user to another page after the successful processing of the form, you can use header(“Location: another_page.php”) . For example, after the user has successfully logged into the system, you can redirect him to the page with his personal account.
  • Automatic redirection: If you want to automatically redirect the user to another page after a certain time or event, you can use header(“Location: another_page.php”) . For example, if you have a page with a message about successful registration, you can redirect the user to the main page after a few seconds.
0

More

Leave a Reply

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

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation