How can the source be extracted from a header("Location: ...") in PHP?
When using the header("Location: ...") function in PHP to redirect a user to another page, the source URL is not directly accessible in the script. To extract the source URL, you can use the $_SERVER['HTTP_REFERER'] variable, which contains the previous page's URL. This can be useful for logging or tracking purposes.
// Extract the source URL from the HTTP_REFERER header
$sourceURL = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'Unknown';
// Output the extracted source URL
echo "Source URL: " . $sourceURL;
Keywords
Related Questions
- In the context of sending HTML emails with PHP, what are the considerations for naming input fields in HTML forms to ensure accurate data transmission to the server-side script?
- In the event of a PHP code injection attack, what steps should be taken to mitigate the impact and restore the system to a secure state?
- How can you differentiate between the current script and include files when retrieving the file name in PHP?