Home > Article > Backend Development > What does var mean in php
The var variable in PHP contains script execution information and can be used to: obtain server environment information (such as server name, operating system) check request status (such as request method) access script information (such as script path) var is a Associative array, keys are strings and values are scalars or arrays. Values can be accessed via $var['key']. Note: "var" is deprecated in PHP 8.0 and higher, it is recommended to use $_SERVER, $_REQUEST, $_COOKIE and $_FILES instead.
The var variable in PHP
var is a built-in variable in PHP. It contains information about the current configuration and status of the executing script.
Purpose
value
var
A variable is an associative array whose keys are strings and whose values are scalar values or arrays. Here are some of the most commonly used keys in the var
variable:
SERVER
: Contains information about the server environment. GET
: Contains information about the current GET request. POST
: Contains information about the current POST request. COOKIE
: Contains information about the cookie in the current request. FILES
: Contains information about the uploaded files in the current request. REQUEST
: Contains information about the current request, including GET, POST, COOKIE, and FILES arrays. SCRIPT_NAME
: The path of the current script. PHP_VERSION
: PHP version. Access
To access the value in a var
variable, you can use the following syntax:
<code class="php">$value = $var['key'];</code>
Example
The following example demonstrates how to use the var
variable to obtain information about the server environment:
<code class="php">echo "服务器名称: " . $var['SERVER']['SERVER_NAME']; echo "操作系统: " . $var['SERVER']['OS']; echo "PHP 版本: " . $var['PHP_VERSION'];</code>
Note
var
Variables are deprecated in PHP version 8.0 and later. The following alternative is recommended: <code class="php">// 获取服务器环境信息 $server = $_SERVER; // 获取请求信息 $request = $_REQUEST; // 获取 cookie 信息 $cookies = $_COOKIE; // 获取文件上传信息 $files = $_FILES;</code>
var
Variables can only be used during script execution and are lost when the script terminates. The above is the detailed content of What does var mean in php. For more information, please follow other related articles on the PHP Chinese website!