To redirect a user to another page using PHP, you can use the header() function. This function sends a raw HTTP header to the browser, which can be used to redirect the user to a new page. Here’s are two simple examples:
Redirect to another page
PHP
<?php
header("Location: /folder/page.php");
exit();
?>
Redirect if the page has been moved permanently
PHP
<?php
header("Location: http://www.domain.com/another-page.php", true, 301);
exit();
?>
Notes:
-
The
header()
function must be called before any output is sent to the browser, including whitespace or HTML tags. If you have any output (such as echo or print statements) before callingheader()
, it will result in an error.If you're getting issues with headers already being sent, ensure you call the
header()
function at the beginning of the script, before any HTML content or whitespace.
Arithmetic operators
Background that adapts to the current season
Calculate the similarity of text
Comparison operators
Count page views in a session
Display a random image
Display a random text
Display array values
Display a time based greeting
Display the current copyright year
Display current date
Display the current date in another language
Display date based on system language settings
Quiz with input fields
Quiz with input fields, multi-steps
Quiz with radio buttons
Quiz with radio buttons, multi-steps
Redirect users to another page
Retrieve checkbox values
Retrieve form input values
Retrieve the value of the selected option
Retrieve the value of the star rating
Store the value of a radio button in a session
Truncate a string to a specified width
Word Wrap