PHP $_SERVER

In PHP, $_SERVER is a predefined variable that contains information about the server and the environment in which the current script is executing. It is an associative array that contains various elements, including:

  • $_SERVER[‘PHP_SELF’] : the name of the current PHP script being executed
  • $_SERVER[‘SERVER_ADDR’] : the IP address of the server
  • $_SERVER[‘SERVER_NAME’] : the name of the server (such as www.example.com)
  • $_SERVER[‘SERVER_SOFTWARE’] : the server software (such as Apache)
  • $_SERVER[‘SERVER_PROTOCOL’]  : the name and revision of the information protocol (such as HTTP/1.1)
  • $_SERVER[‘REQUEST_METHOD’] : the request method used to access the page (such as GET, POST, or HEAD)
  • $_SERVER[‘QUERY_STRING’] : the query string (the part of the URL after the ? character)
  • $_SERVER[‘HTTP_REFERER’] : the referring page (the page the user came from)
  • $_SERVER[‘HTTP_USER_AGENT’] : the user agent string (the browser and operating system being used)
  • $_SERVER[‘REMOTE_ADDR’] : the IP address from which the user is viewing the current page.

These are just a few examples of the information that can be accessed using $_SERVER . By accessing this information, you can customize the behavior of your PHP script based on the specific server environment and user request.

Scroll to Top