How can you determine which page (URL) called the current page in PHP?
To determine which page (URL) called the current page in PHP, you can use the $_SERVER['HTTP_REFERER'] variable. This variable contains the URL of the previous page that linked to the current page. You can use this information to track where the user came from before landing on the current page.
if(isset($_SERVER['HTTP_REFERER'])){
$previousPage = $_SERVER['HTTP_REFERER'];
echo "Previous page URL: " . $previousPage;
} else {
echo "No previous page information available.";
}
Keywords
Related Questions
- What potential pitfalls should be considered when retrieving user information from a database to send birthday emails in PHP?
- How can validation tools like the W3C validator help identify and resolve issues with PHP-generated HTML output, especially related to quotation marks and syntax errors?
- What are common mistakes made when decoding JSON data in PHP?