PHP - Predefined variables

    PHP supports a large number of predefined variables and arrays that are globally available to use in your script. Below is the list of all variables and arrays. These are also known as superglobals.

    Variable Description
    $_GLOBALS This contains a reference to the variable that is global to the script.
    $_SERVER This contains the information about the server header, path and script location and this information is created by the server.
    $_GET This associative array will be passed during the HTTP GET method.
    $_POST This associative array will be passed during the HTTP POST method.
    $_FILES This associative array can be used to access the uploaded file information.
    $_REQUEST This associative array contains the information of $_GET, $_POST and $_COOKIE.
    $_COOKIE This associative array used to access the details of the cookie.
    $_SESSION This associative array is used to access data of the session.
    $_PHP_SELF It is a string that contains the script file name.
    $php_errormsg This string will contain the last error message generated by PHP.

    Web server creates some entries that can be accessed using $_SERVER variable that supports many other variables. It may be possible that some of the variables below may not be supported by your web server.

    $_SERVER variables Description
    $_SERVER['PHP_SELF'] This will contain the file name of the executing script.
    $_SERVER['argv'] This contains the query string that is passed to the script.
    $_SERVER['argc'] If the script is running via command prompt then it will contain the passed command line parameters.
    $_SERVER['GATEWAY_INTERFACE'] This indicates which which CGI configuration version is used by the script.
    $_SERVER['SERVER_ADDR'] Contains the IP address of the current script executing server.
    $_SERVER['SERVER_NAME'] This will refer to the server name where the script is executing.
    $_SERVER['SERVER_SOFTWARE'] This contains the server identification string when responding to requests and is present in the header.
    $_SERVER['SERVER_PROTOCOL'] This specifies the protocol of the server while requesting a page.
    $_SERVER['REQUEST_METHOD'] It specifies which request method is used when you are accessing a page.
    $_SERVER['REQUEST_TIME'] It specifies the timestamp when the request is made.
    $_SERVER['QUERY_STRING'] It specifies the string while accessing a page.
    $_SERVER['DOCUMENT_ROOT'] It specifies the directory where the file is executing.
    $_SERVER['HTTP_ACCEPT'] It contains the accept header information of HTTP requests.
    $_SERVER['HTTP_ACCEPT_CHARSET'] It contains the accept-charset header information of HTTP requests.
    $_SERVER['HTTP_ACCEPT_ENCODING'] Contain information of accept-encoding HTTP header.
    $_SERVER['HTTP_ACCEPT_LANGUAGE'] Contain information of accept-language HTTP header.
    $_SERVER['HTTP_CONNECTION'] It contains the information of the connection header of the HTTP request.
    $_SERVER['HTTP_HOST'] Contains host header information of HTTP request.
    $_SERVER['HTTP_REFERER'] Refers to the current page user agent page address.
    $_SERVER['HTTP_USER_AGENT'] This string refers to the user agent which is accessing the file.
    $_SERVER['HTTPS'] This value is set in case the page is accessing via HTTPS protocol.
    $_SERVER['REMOTE_ADDR'] The IP address of the user viewing the current page.
    $_SERVER['REMOTE_HOST'] The hostname of the user viewing the current page.
    $_SERVER['REMOTE_PORT'] Specifies the port of your machine that is communicating to the webserver.
    $_SERVER['SCRIPT_FILENAME'] Specifies the currently executing script’s pathname.
    $_SERVER['SERVER_ADMIN'] This specifies the server_admin directive value in the server configuration file.
    $_SERVER['SERVER_PORT'] This specifies which port is used for web server communication.
    $_SERVER['SERVER_SIGNATURE'] This string contains a server version and a virtual hostname added to the server-generated page.
    $_SERVER['PATH_TRANSLATED'] This specifies the current script’s filesystem-based path.
    $_SERVER['SCRIPT_NAME'] Specifies the path of the current script.
    $_SERVER['REQUEST_URI'] Specifies the URL given to access any page.
    $_SERVER['PHP_AUTH_DIGEST'] This variable is set to the authorization header sent by the client in case if it running under Apache.
    $_SERVER['PHP_AUTH_USER'] This is the username specifies by the user.
    $_SERVER['PHP_AUTH_PW'] This is the password given by the user.
    $_SERVER['AUTH_TYPE'] When running PHP doing HTTP authentication this variable is set to authentication type.

    People are also reading: