PHP超级全局变量总结
PHP超级全局变量总结
silicon1985 的 重要的PHP超级全局变量总结PHP有9个预定义变量数组,分别总结如下:
1、$_SERVER
$_SERVER超级全局变量包含由web服务器创建的信息,它提供了服务器和客户配置及当前请求环境的有关信息。根据服务器不同,$_SERVER中的变量值和变量个数会有差别,不过一般都可以找到CGI1.1规范中定义的变量。其中包括:
$_SERVER[ 'HTTP_REFERER' ] ; 引导用户到达当前位置的页面的URL ;
$_SERVER[ 'REMOTE_ADDR‘ ] ; 客户IP地址 ;
$_SERVER[ ’REQUEST_URI‘ ] ; URL的路径部分。如果URL是 [url]http://www.example.com/blog/apache/index.html[/url] ,那么URI就是/blog/apache/index.html 。
$_SERVER[ 'HTTP_USER_AGENT' ] ; 客户的用户代理,一般会提供操作系统和浏览器的有关信息。
2、$_GET
$_GET超级全局变量包含使用GET方法传递的参数的有关信息。如果请求URL为[url]http://www.example.com/index.html?cat=apache&id=157[/url], 就可以使用$_GET超级全局变量访问如下变量:
$_GET[ 'cat' ] = "apache" ;
$_GET[ 'id' ] = "157" ;
默认情况下,要访问通GET方法传递的变量,$_GET超级全局变量是唯一的途径。
3、$_POST
$_POST超级全局变量包含用POST方法传递的参数的有关信息。
通过脚本subscribe.php,就可以使用下面的POST变量:
$_POST[ 'email' ] = " jason@example.com " ;
$_POST[ 'pswd' ] = "rainyday" ;
$_POST[ 'subscribe' ] = "subscribe!" ;
与$_GET一样,在默认情况下,$_POST超级全局变量是访问POST变量的唯一途径。
4、$_COOKIE
$_COOKIE超级全局变量存储了通过HTTP cookie传递到脚本的信息。这些cookie一般是由以前执行的PHP脚本通过PHP函数setcookie ( ) 设置的。例如,假设使用 setcookie ( )存储了一个名为 example.com、值为ab2213的cookie。以后就可以通过调用$_COOKIE[ ' example.com' ]来获得这个值。
5、$_FILES
$_FILES超级全局变量包含通过POST方法向服务器上传的数据的有关信息。这个超级全局变量与其他的变量有所不同,它是一个二维数组,包含5个元素。第一个下标标示表单的文件上传元素名;第二个下标是五个预定义下标之一,这些下标描述了上传文件的某个属性:
△ $_FILES[ 'upload-name' ][ 'name' ]; 从客户端向服务器上传文件的文件名;
△ $_FILES[ 'upload-name' ][ 'type' ]; 上传文件的MIME类型,这个变量是否赋值取决于浏览器的功能。
△ $_FILES[ 'upload-name' ][ 'size' ]; 上传文件的大小(以字节为单位);
△ $_FILES[ 'upload-name' ][ 'tmp_name' ]; 上传之后,将此文件移到最终位置之前赋予的临时名。
△ $_FILES[ 'upload-name' ][ 'error' ]; 上传状态码。尽管这个变量的名为 error ,但实际上在成功的情况下也会填写这个变量。它有五个可能的值:
■ UPLOAD_ERR_OK 文件成功上传
■ UPLOAD_ERR_INI_SIZE 文件大小超出了 upload_max_filesize 指令所指定的最大值。
■ UPLOAD_ERR_FORM_SIZE 文件大小超出了MAX_FILE_SIZE 隐藏表单域参数(可选)指定的最大值。
■ UPLOAD_ERR_PARTIAL 文件只上传了一部分
■ UPLOAD_ERR_NO_FILE 上传表单中没有指定文件
6、$_ENV
$_ENV超级全局变量提供PHP解析所在服务器环境的有关信息。此数组中的变量包括:
△ $_ENV[ 'HOSTNAME' ] 服务器的主机名
△ $_ENV[ 'SHELL' ] 系统 shell
7、$_REQUEST
$_REQUEST超级全局变量是一个全能选手,它记录了通过各种方法传递给脚本的变量,特别是GET ,POST 和 COOKIE 。 这些变量的顺序不依赖于它们在发送脚本中出现的顺序,而是依赖于 variables_order 配置指令所指定的顺序。建议少用这个超级变量,因为它不够安全。
8、$_SESSION
$_SESSION 超级全局变量包含与所有会话有关的信息。注册会话信息能为你提供便利,这样就能在整个网站中引用这些会话信息,而无需通过GET或POST显示的传递数据。
9、$GLOBALS
$GLOBALS 超级全局变量数组可以认为是超级全局变量的超集,包含全局作用域内的所有变量。执行下面的代码可以查看$GLOBALS 中所有的变量。
print '
' ;</p> <p> print_r ($GLOBALS);</p> <p> print '

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Environment variables are the path to the location (or environment) where applications and programs run. They can be created, edited, managed or deleted by the user and come in handy when managing the behavior of certain processes. Here's how to create a configuration file to manage multiple variables simultaneously without having to edit them individually on Windows. How to use profiles in environment variables Windows 11 and 10 On Windows, there are two sets of environment variables – user variables (apply to the current user) and system variables (apply globally). However, using a tool like PowerToys, you can create a separate configuration file to add new and existing variables and manage them all at once. Here’s how: Step 1: Install PowerToysPowerTo

Strict mode was introduced in PHP7, which can help developers reduce potential errors. This article will explain what strict mode is and how to use strict mode in PHP7 to reduce errors. At the same time, the application of strict mode will be demonstrated through code examples. 1. What is strict mode? Strict mode is a feature in PHP7 that can help developers write more standardized code and reduce some common errors. In strict mode, there will be strict restrictions and detection on variable declaration, type checking, function calling, etc. Pass

Instance variables in Java refer to variables defined in the class, not in the method or constructor. Instance variables are also called member variables. Each instance of a class has its own copy of the instance variable. Instance variables are initialized during object creation, and their state is saved and maintained throughout the object's lifetime. Instance variable definitions are usually placed at the top of the class and can be declared with any access modifier, which can be public, private, protected, or the default access modifier. It depends on what we want this to be

PHP function introduction—strpos(): Check whether a variable is a string In PHP, is_string() is a very useful function, which is used to check whether a variable is a string. When we need to determine whether a variable is a string, the is_string() function can help us achieve this goal easily. Below we will learn about how to use the is_string() function and provide some related code examples. The syntax of the is_string() function is very simple. it only needs to

Using Ajax to obtain variables from PHP methods is a common scenario in web development. Through Ajax, the page can be dynamically obtained without refreshing the data. In this article, we will introduce how to use Ajax to get variables from PHP methods, and provide specific code examples. First, we need to write a PHP file to handle the Ajax request and return the required variables. Here is sample code for a simple PHP file getData.php:
![Internal error: Unable to create temporary directory [Resolved]](https://img.php.cn/upload/article/000/000/164/168171504798267.png?x-oss-process=image/resize,m_fill,h_207,w_330)
Windows system allows users to install various types of applications on your system using executable/setup files. Recently, many Windows users have started complaining that they are receiving an error named INTERNALERROR:cannotCreateTemporaryDirectory on their systems while trying to install any application using an executable file. The problem is not limited to this but also prevents the users from launching any existing applications, which are also installed on the Windows system. Some possible reasons are listed below. Run the executable to install without granting administrator privileges. An invalid or different path was provided for the TMP variable. damaged system

Python is widely used in a wide range of fields with its simple and easy-to-read syntax. It is crucial to master the basic structure of Python syntax, both to improve programming efficiency and to gain a deep understanding of how the code works. To this end, this article provides a comprehensive mind map detailing various aspects of Python syntax. Variables and Data Types Variables are containers used to store data in Python. The mind map shows common Python data types, including integers, floating point numbers, strings, Boolean values, and lists. Each data type has its own characteristics and operation methods. Operators Operators are used to perform various operations on data types. The mind map covers the different operator types in Python, such as arithmetic operators, ratio

Storage classes specify the scope, lifetime, and binding of variables. To fully define a variable, it is necessary to mention not only its "type" but also its storage class. A variable name identifies a physical location in computer memory where a set of bits is allocated to store the variable's value. Storage class tells us the following factors - Where are the variables stored (in memory or CPU registers)? If not initialized, what is the initial value of the variable? What is the scope of a variable (the scope within which the variable can be accessed)? What is the life cycle of a variable? The lifetime of a lifetime variable defines the duration for which the computer allocates memory (the duration between memory allocation and deallocation). In C language, variables can have automatic, static or dynamic life cycle. Automatic - create a life cycle with automatic
