Skip to content
PHP Logo

What is the difference between PHP_SELF and _SERVER["REQUEST_URI"] in PHP?

The main difference between PHP_SELF and _SERVER["REQUEST_URI"] in PHP is that PHP_SELF contains the filename of the currently executing script, while _SERVER["REQUEST_URI"] contains the URI which was given in order to access the page. If you want to get the full URL of the current page, including query parameters, you should use _SERVER["REQUEST_URI"].

php
// Using _SERVER["REQUEST_URI"] to get the full URL of the current page
$current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
echo $current_url;