外界PHP变量_PHP
HTML表单(GET和POST)
当表单被提交给PHP脚本时,从该表单获得的变量将自动的被该PHP脚本设置为可用。请参考如下示例:
Example 5-2. Simple form variable (简单的表单变量)
当提交之后,PHP将建立一个变量“$name”,它将包含任何在表单中输入在“Name”中的内容。
PHP同时也知道如何安排表单变量的上下文关系,但是仅仅限于一次。您可以,例如,将一组变量同时叙述,或者使用这个特性来重新从多重选择输入中获得值:
Example 5-3. More complex form variables
如果PHP的track_var特性被打开了,任何关于它的结构设置或者指示,然后经由POST或GET模式的变量提交将发觉使用全局联合数组“$HTTP_POST_VARS”和“$HTTP_GET_VARS”是合适的。
图形提交变量名字
当提交一个表单时,有可能使用一幅图象来代替标准的带标签的提交按钮,例如:
当用户点击该图象的任何位置时,相应的表单将被使用两个附加的变量(sub_x和sub_y)来传送到服务器上。他们包含用户点击在该图形上的相应位置信息。这将包含从浏览器发出的真实变量名字(甚至包含下划线),但是PHP将会把它自动的转化成带下划线的形式。
HTTP Cookies
PHP当然的支持使用Netscape's Spec定义的HTTP Cookies。Cookies是一种在远程浏览器上存放数据的装置,用于跟踪和鉴定用户的身份。您可以使用SetCookie()函数来对cookies进行设置。Cookies是HTTP头的一部分,所以SetCookie程序必须在被进行向浏览器输出前被调用。这和Header()函数的设置是类似的。任何从服务器送到用户处的cookies将自动的被转化成为一个PHP变量,就象使用GET和POST模式的数据一样。
如果您希望对单个的cookie分派多值,只要在cookie的名字后面简单的加上一个“[ ]”即可。例如:
SetCookie ("MyCookie[]", "Testing", time()+3600);
注意,如果不是在您的浏览器上的域或者路径不一样的话cookie将会使用相同的名字来顶替先前的一个cookie。所以,对于购物单应用程序,您可能希望保持一个计数器同时通过cookie来传送它,例如:
Example 5-4. SetCookie Example (设置Cookie的例子)
$Count++;
SetCookie ("Count", $Count, time()+3600);
SetCookie ("Cart[$Count]", $item, time()+3600);
环境变量
PHP自动的使用环境变量作为PHP的普通变量,例子如下。
echo $HOME; /* Shows the HOME environment variable, if set. */
既然信息随同GET,Post,Cookie等机制被传递进来,并且自动创建了PHP变量,有时最好是准确的从外界环境中读出一个变量以确信你正在使用正确的版本。getenv()函数就是做这个工作的,你也可以使用putenv()函数来设置一个环境变量。

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

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
