100 pre-defined ultra-Global Array ①-Principle Analysis $ _ GET Update Time:, January 1, April 21, 2013 Source: Now we are doing project string knowledge points. first, I want to explain to you what is a global variable in predefine hyperglobal variables in PHP? Php $ a23; global variable because the variable is in the entire scope (in this
100 pre-defined ultra-Global Array ①-Principle Analysis $ _ GET Update Time:, January 1, April 21, 2013 Source: Now we are doing project string knowledge points. first, I want to explain to you what is a global variable in predefine hyperglobal variables in PHP? Php $ a = 23; // global variable because the variable is in the entire scope (in this
100 pre-defined hyper-Global Array ①-Principle Analysis $ _ GET
Updated on: November 11, April 21, 2013 Source:
Now we are doing a project string of knowledge points.
First, we will explain the definition of a global variable.
Predefine hyperglobal variables in PHP
① What is a global variable
$ A = 23; // global variable because it is visible throughout the scope (in this PHP file)
Function test (){
// If you want to use global $;
Global $;
$ A = 45;
}
Test ();
Echo $;
?>
② What is a super global variable
In addition to the features of global variables, hyper-global variables can be directly used without declaration.
Quick Start
// Super global variable
$ _ SERVER ['shanghai'] = "Han shunping ";
Echo"
";
echo print_r($_SERVER);
echo "
"
The reason for providing an ultra-global array is to allow programmers to write PHP programs more conveniently and quickly.
③ Nine PHP types are provided
1. $ _ GET
2. $ _ POST
3. $ _ REQUEST
4. $ _ SERVER
5. $ _ ENV
6. $ _ FILE
7. $ _ COOKIE
8. $ _ SESSION
9. $ GLOBALS
Explain one by one
1. $ _ GET
Use the $ _ GET principle to analyze the ins and outs of data...
Schematic diagram:
Upload 3 minutes ago
Download Attachment(60.59 KB)
$ _ GET actually used.
The ghost client (browser) transmits information to the server through a hyperlink
Case 1
Test. php page
// Urlencode Encoding
Echo "Beijing good & name = xiaoming '> Transfer Data ";
?>
Interview question: How can I handle the Chinese garbled characters of the data submitted by hyperlink?
1. For the later version of IE browser, no need to deal
2. urlencode () encoding is required for 5.5 and 6.0 ie.
3. Try to use letters and numbers.
A. php page
Echo"
";
echo print_r($_GET);
echo "
";
// If you want to extract a data, you can use the subscript name
Echo $ _ GET ['name'];
?>
Check the odd Chinese Characters in ie5.5 and ie 6.
Solution 1.
Add a space to the odd number of Chinese characters, and then receive it on the server. Remove the empty lines trim () at both ends ()
Solution 2:
Use urlencode and urldecode Functions
On the test. php page
// Encode the Chinese url.
$ Str = urlencode ("Beijing good ");
Echo "Transfer Data ";
?>
// The a. php page receives the request normally.
Echo"
";
echo print_r($_GET);
echo "
";
// If you want to extract a certain data, you can use the subscript name. If the php version is low, it may be Chinese and you need to use urldecode () to decrypt the data.
Echo "--". $ _ GET ['city'];
?>
_ GET can also receive forms to submit data in get Mode
** Regiseter2.php ***
// See how to receive
Echo"
"; echo print_r($_POST);
echo "
";
// Interests
$ Name = $ _ POST ['username'];
$ Pwd = $ _ POST ['passwd'];
// How to receive data submitted by checkbox
$ Hobbies =$ _ POST ['hobby'];
Echo "personal information is as follows
";
Echo "$ name -- $ pwd ";
// Print_r ($ hobbies );
Echo "this person's hobby ";
Foreach ($ hobbies as $ key => $ val ){
Echo"
$ Key = $ val ";
}
Echo"
Your location is ";
$ City = $ _ POST ['city'];
Echo $ city;
Echo"
My personal profile is as follows ";
$ Intro = $ _ POST ['intro'];
Echo"
$ Intro ";
Echo "view investigation"
?>
There is also a drop-down box demonstration
10 min:
You write a survey on the happiness of life, and then put the survey information, Stored in the database. To see if the data can be obtained and displayed to the user.
Get data submission is mainly
The default value is get.
// When this method is redirected, it is also submitted to OK. php In get mode.
Header ("Location: OK. php? Aaa = xiaoming ");
?>
For the difference between post and get, see ppt
① Security post> get
② Data transmission size [browser] post> get
③ It is convenient to save to favorites get.
$ _ REQUST
Definition: $ _ REQUST contains $ _ GET/$ POST/$ _ COOKIE array.
Quick Start:
Here is a case study:
Echo"
"; echo print_r($_REQUEST);
echo "
";
// How to retrieve a value
// $ _ REQUEST can receive get REQUEST data, post REQUEST, cookie ..
// Therefore, this variable cannot be trusted.. $ _ GET $ _ POST is not recommended.
Echo $ _ REQUEST ['a'];
// If you are not sure about get/post
If ($ _ SERVER ['HTTP _ method'] = "post "){
$ Echo $ _ POST ['name'];
} Else if ($ _ SERVER ['HTTP _ method'] = "get "){
// Receive with _ GET.
}
?>
Note:
1. Do not use $ _ REQUEST frequently,
2. If you are not sure about _ GET/POST
This is what you can do when receiving data.
If ($ _ SERVER ['request _ method'] = "POST "){
$ Echo $ _ POST ['name'];
} Else if ($ _ SERVER ['request_method '] = "GET "){
// Receive with _ GET.
}
Pre-defined ultra-Global Array ③-$ _ SERVER $ _ ENV $ GLOBALS
$ _ ENV
This global array can be used to obtain environment variables, which are disabled by default in php5.3, but can be started and enabled in the php. ini file.
Variables_order = "EGPCS"
Note: Do not enable it in the development and production environments.
$ _ FILE/$ _ COOKIE/$ _ SESSION
Later
$ GLOBALS
A global combination array containing all the variables. The variable name is the array key [manual]
A custom global variable is automatically managed by $ _ GLOBALS.
Case:
Echo "aaaa ";
Echo"
"; echo print_r($GLOBALS);
echo "
";
?>
When you define a global variable, the variable will also be managed by $ GLOBALS.
$ A = 900;
Echo"
”; print_r($GLOBALS);
echo “
"
?>
Case study: