How Can I Redirect a PHP Page After a Function Executes?
Nov 27, 2024 pm 10:38 PMPHP Page Redirection After Executing a Function
Can PHP redirect to a different page after completing a specific function? Yes, you can use the header function to achieve this.
To redirect to a page called "user.php" located in the same root folder, you would use the following code:
header("Location: user.php"); exit();
It is important to call exit() after the header function to prevent any code below it from executing.
Here's an example of how you might use this in the code you provided:
if (...) { // I am using echo here. } else if ($_SESSION['qnum'] > 10) { session_destroy(); echo "Some error occured."; header("Location: user.php"); // Redirect to "user.php" exit(); }
Note: Ensure that there is no output before the header function is called, as this could break the redirect. Additionally, verify that the code is executed before any other output is sent to the browser.
The above is the detailed content of How Can I Redirect a PHP Page After a Function Executes?. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel

Build a React App With a Laravel Back End: Part 2, React

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

12 Best PHP Chat Scripts on CodeCanyon

Announcement of 2025 PHP Situation Survey
