What are some common server variables that can be used to check the URL in PHP?

In PHP, you can use server variables like $_SERVER['REQUEST_URI'] or $_SERVER['PHP_SELF'] to check the URL of the current page. These variables provide information about the requested URL, allowing you to manipulate or validate it as needed. By accessing these server variables, you can effectively work with URLs in your PHP scripts.

// Check the URL using $_SERVER['REQUEST_URI']
$currentUrl = $_SERVER['REQUEST_URI'];
echo "Current URL: " . $currentUrl;

// Check the URL using $_SERVER['PHP_SELF']
$currentUrl = $_SERVER['PHP_SELF'];
echo "Current URL: " . $currentUrl;