How can the previous URL be determined in PHP?

To determine the previous URL in PHP, you can use the $_SERVER['HTTP_REFERER'] variable. This variable contains the URL of the previous page that referred the user to the current page. This can be useful for tracking where users are coming from or for implementing back functionality on a website.

$previous_url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'No previous URL';
echo $previous_url;