Variables are predefined in PHP
PHP provides a large number of predefined variables for any script that runs. PHP provides an additional set of arrays containing variables from Web Server, environment variables and user input. These new arrays are called Superglobal.
All the following variables are automatically available in all ranges.
Superglobal in PHP
You can use all of the following variables anywhere in your PHP code.
Variable Description $ GLOBALS Contains a reference to each variable that is currently available within the global scope of the script. The key of each array is the names of these global variables. $ _SERVER This is an array containing information such as header, path and script location. Entries in this array are created by the Web Server. There is no guarantee that each Web Server will provide any variable in this variable form. You follow the next section to get a list of all Server variables. $ _GET An associative array of variables passed to the current script via the HTTP GET method. $ _POST An associative array of variables passed to the current script via the HTTP POST method. $ _FILES An associative array of items uploaded to the current script via HTTP POST method. $ _REQUEST An associative array of contents of $ _GET, $ _POST and $ _COOKIE. $ _COOKIE An associative array of variables passed to the current script via HTTP cookies. $ _SESSION An associative array containing session variables available for the current script. $ _PHP_SELF A string containing the name of the PHP script file in which it is called. $ php_errormsg $ php_errormsg is a text variable of the last error message generated by PHP.Turn $ _SERVER in PHP
The variable $ _SERVER is an array containing information such as header, path, and script location. Entries in this array are created by the Web Server. There is no guarantee that each Web Server will provide any variable in this form of Server variable.
Variable Description $ _SERVER ['PHP_SELF'] The file name of the script is currently executing, relative to the Document root. $ _SERVER ['argv'] Array parameters are passed to the script. When that script runs on the command line, it provides C-style type access to command line parameters. When called via the GET method, this variable will contain the query string. $ _SERVER ['argc'] Contains the number of command line parameters passed to the script if run on the command line. $ _SERVER ['GATEWAY_INTERFACE'] Server is using which version of CGI specification, for example 'CGI / 1.1'. $ _SERVER ['SERVER_ADDR'] The server's IP address that the script is executing. $ _SERVER ['SERVER_NAME'] Name of the host host that the script is executing. If the script is running on a virtual host, this variable will be the value defined for that virtual host. $ _SERVER ['SERVER_SOFTWARE'] Server identification string, provided in the header when responding to requests. $ _SERVER ['SERVER_PROTOCOL'] The name and version of the information protocol through which the page is requested, for example: 'HTTP / 1.0'; $ _SERVER ['REQUEST_METHOD'] Which request method is used to access the page, for example: 'GET', 'HEAD', 'POST', 'PUT'. $ _SERVER ['REQUEST_TIME'] Is the timestamp of the required start. Available from PHP 5.1.0. $ _SERVER ['QUERY_STRING'] The query string through which the page is accessed. $ _SERVER ['DOCUMENT_ROOT'] The Document root directory that the script is executing, as defined in the Server configuration file. $ _SERVER ['HTTP_ACCEPT'] Content of Accept: header from the current request, if there is one. $ _SERVER ['HTTP_ACCEPT_CHARSET'] Content of Accept-Charset: header from the current request, if there is one. For example: 'iso-8859-1, *, utf-8' $ _SERVER ['HTTP_ACCEPT_ENCODING'] Content of Accept-Encoding: header from the current request, if there is one. For example: 'gzip' $ _SERVER ['HTTP_ACCEPT_LANGUAGE'] Content of Accept-Language: header from the current request, if there is one. For example: 'en' $ _SERVER ['HTTP_CONNECTION'] The content of the Connection: header from the current request, if there is one. For example: 'Keep-Alive' $ _SERVER ['HTTP_HOST'] The content of the Host: header from the current request, if there is one. $ _SERVER ['HTTP_REFERER'] The address of the page that directs the user agent to the current page. $ _SERVER ['HTTP_USER_AGENT'] This is the string representing the user agent accessing the page. Typical examples are: Mozilla / 4.5 [en] (X11; U; Linux 2.2.9 i586). $ _SERVER ['HTTPS'] Set to a non-empty value if the script is queried via HTTPS protocol. $ _SERVER ['REMOTE_ADDR'] IP address from which the user observes the current page. $ _SERVER ['REMOTE_HOST'] Host name from which the user observes the current page. $ _SERVER ['REMOTE_PORT'] The port (port) is being used on the user's computer to communicate with the Web Server. $ _SERVER ['SCRIPT_FILENAME'] The absolute pathname of the script is currently executing. $ _SERVER ['SERVER_ADMIN'] The value provided for SERVER_ADMIN directive (with Apache) in the Web Server configuration file. $ _SERVER ['SERVER_PORT'] The port (port) on the Server computer is being used by the Server to communicate. The default setting is '80'. $ _SERVER ['SERVER_SIGNATURE'] The string contains the Server version and the host name that is added to the page created by the Server, if enabled. $ _SERVER ['PATH_TRANSLATED'] Path for the current script. $ _SERVER ['SCRIPT_NAME'] Contains the path of the current script. This variable is useful for pages that need to point to themselves. $ _SERVER ['REQUEST_URI'] URI provided to access this page, eg '/index.html' $ _SERVER ['PHP_AUTH_DIGEST'] When running under Apache as the module executing Digest HTTP authentication, this variable is Set the 'Authorization' header sent by the Client. $ _SERVER ['PHP_AUTH_USER'] When running under Apache or IIS (ISAPI on PHP 5) as a module doing HTTP authentication, this variable is set to the username provided by the user. $ _SERVER ['PHP_AUTH_PW'] When running under Apache or IIS (ISAPI on PHP 5) as the module is executing HTTP authentication, this variable is set to the password provided by the user. $ _SERVER ['AUTH_TYPE'] When running under Apache as a module implementing HTTP authenticated, this variable is set to authentication type.Follow tutorialspoint
Previous article: Standard writing code in PHP
Next lesson: Regular Expression in PHP
4 ★ | 1 Vote
You should read it
May be interested
- Use variables in Shella variable is a string of characters from which we assign a value. the assigned value can be a number, text, file name, device or any other type of data.
- Scope rules in programming Ca scope in any program is an area in the program where a defined variable exists and outside of that range the variable cannot be accessed.
- stddef.h in Cthe file header named stddef.h in c library defines various types of variables and macros. many of these definitions are also present in other headers.
- PHP for PERL Programmersthis chapter will list some of the major similarities and differences between php and perl. this helps perl programmers understand php faster and avoid common errors.
- Special variables in Unix / Linuxthe previous tutorial has warned about using special characters in your variable name. this is because these characters are used in the names of special variables in unix. these variables are kept for special functions.
- How to set and list environment variables in Linuxif you want to do something that requires using the command line, you will still need to know about environment variables. this may seem like a complicated term, but actually environment variables are easy to understand.
- C ++ exercises have solutions (sample code) for variables, data types, and operatorsin the previous c ++ exercises, tipsmake.com introduced, you were acquainted with many types of lessons, from simple to complex. in this c ++ exercise, we will become familiar with c ++ exercises on variables and data types in c ++.
- Learn about Permission and Role Based Access Control - RBAC (part 1)in essence, microsoft exchange server 2010 has been improved and integrated with new role based access control - rbac, and this model has provided users with more ways to monitor and initialize like assigning rights to different admin accounts. and these assigned roles will respond
- Variable in C programminga variable in c is nothing but a name given to storage memory so that the program can be manipulated. each variable in c has a defined type, to determine the size and layout for that variable memory. the range of values that can be stored in memory, setting of expressions can be applied to variables.
- Data type in C / C ++data type in c / c ++ while working with any programming language, you need to use various types of variables to store information. variables, nothing but memory locations are reserved for saving values. that is, when you create a variable, you reserved some space in memory for that variable.