PHP defines global variables, static variables, local variable definition instances

Source: Internet
Author: User
Tags file upload http cookie http post

$globals Array

function TestFunction () {
echo $globals ["php_self"];
}
TestFunction ();

This program uses global definitions
function TestFunction () {
Global $s;
Echo $s;
}
$s = ' this is www.111cn.net ';
TestFunction ();

Examples of static variables
function TestFunction () {
Static $mystr;
$mystr. = "111cn.net";
echo $mystr. " <br> ";
}
TestFunction (); 111cn.net
TestFunction (); 111cn.net111cn.net
TestFunction (); 111cn.net111cn.net111cn.net

Ordinary variable
function TestFunction () {
$mystr. = "Www.111cn.net";
echo $mystr. " <br> ";
}
TestFunction (); Www.111cn.net

Here's a quick introduction to the Super global variables in PHP that have those

$GLOBALS contains a reference to the global scope valid variable for each current script, instance

$GLOBALS [' site '];

$_server variables are set by the Web server or directly associated with the execution environment of the current script

echo $_server[' Document_root '];

$_get URL Request submit to script variable

echo $_get[' AC ']

$_post HTTP POST Method submit to script variable

echo $_post[' AB ']

$_cookie HTTP Cookie Method submit to script variable

Setcookie (' Load ', ' www.111cn.net ', Time () +3600*24, '/', ' 192.168.0.110 ');
$cookis = $_cookie[' Loaddomain '];

$_files HTTP POST File Upload and submit to script variable

<form name= "Form1" enctype= "Multipart/form-data" method= "POST" action= "" >
<input type= "File" name= "file" >
<input type= "Submit" name= "Submission" value= "submitted" >
</form>

Output value:
Print_r ($_files[' file '));

  array
   (
   [name] => 45457.jpg
   [type] = > Image/pjpeg
   [tmp_name] => c:windowstempphpd7.tmp
   [error] => 0
   [size] => 10974
  
  
 //$_env deprecated
 //$_ The REQUEST is submitted by the Get,post and COOKIE mechanisms to the script's variables, so the array is not secure and inefficient.
  
  $_request[' BB '//The data that will be automatically submitted is post,get form

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.