About Privacy Terms

PHP Server Variables ($_SERVER) | PHP

Home / PHP Variables / PHP Server Variables ($_SERVER) | PHP

Share Now

 

PHP Server Variables

 

PHP Server Variables ($_SERVER)

 

$_SERVER is a PHP superglobal variable that contains information about the server and the environment in which a PHP script is running. It is an associative array that can be used to access server and environment variables, such as the script's name, the current directory, the server software version, and so on. Some common elements of $_SERVER include:

  • $_SERVER['PHP_SELF']: the name of the script that is currently being executed, relative to the document root.
  • $_SERVER['SERVER_NAME']: the name of the server on which the script is running.
  • $_SERVER['HTTP_HOST']: The host name from HTTP Host header
  • $_SERVER['HTTP_USER_AGENT']: the user agent string sent by the browser, this can be used to detect the browser and version, platform and even mobile devices.
  • $_SERVER['REMOTE_ADDR']: the IP address of the client connecting to the server.
  • $_SERVER['REQUEST_URI']: the URI which was given in order to access this page; for instance '/index.html'.
  • $_SERVER['REQUEST_METHOD']: which request method was used to access the page; i.e. 'GET', 'HEAD', 'POST', 'PUT'.
  • $_SERVER['SCRIPT_NAME']: contains the current script's path.
  • $_SERVER['SCRIPT_FILENAME']: contains the full path and filename of the current script.
  • $_SERVER['SERVER_PROTOCOL']: the server protocol, for example HTTP/1.1
  • $_SERVER['SERVER_SOFTWARE']: the server software, for example Apache/2.4.43 (Win64) PHP/7.4.12
  • $_SERVER['HTTP_REFERER']: the previous page from which the user navigated to the current page.

 

It should be noted that The $_SERVER superglobal depends on the web server hosting your PHP scripts, it means some of the key-value pairs may not be available or may have different value for different web servers.

 

Share With Family & Friends

Image
VPS Hosting
10 Best VPS for Minecraft Server | TOP 10

10 Best VPS for Minecraft Server.

Image
VPS Hosting
10 Best VPS for a FiveM Server | TOP 10

10 Best VPS for a FiveM Server.

Image
VPS Hosting
10 Best VPS for Mail Server | TOP 10

10 Best VPS for Mail Server.

Image
Game Hosting
10 Best FiveM Server Hosting | TOP 10

10 Best FiveM Server Hosting.

Image
Dedicated Hosting
10 Best Dedicated Server Hosting in USA | TOP 10

10 Best Dedicated Server Hosting in USA.

Image
Game Hosting
10 Best Factorio Server Hosting | TOP 10

10 Best Factorio Server Hosting.