1. 概述 PHP环境变量主要有: $GLOBALS[]:储存当前脚本中的所有全局变量,其KEY为变量名,VALUE为变量 $_SERVER[]:当前WEB服务器变量数组 $_GET[]:存储以GET方法提交表单中的数据 $_POST[]:存储以POST方法提交表单中的数据 $_COOKIE[]:取得或设置用户浏
1. 概述
2. $GLOBALS[]
GLOBALS是由已定义全局变量组成的数组,变量名就是数组的索引,eg:
$ENTER = "<br>"; $var1 = 5; $var2 = 10; print $GLOBALS['var1'] . $ENTER ; print $GLOBALS['var2'] . $ENTER ;
$ENTER = "<br>"; print "SERVER_ADDR:" . $_SERVER['SERVER_ADDR'] . $ENTER;
参考:http://www.php.net/manual/zh/reserved.variables.server.php
4. $_GET和_POST//_GET echo "name:" . $_GET["name_get"] . $ENTER ; echo "age:" . $_GET["age_get"] . $ENTER; //_POST echo "name:" . $_POST["name_post"] . $ENTER ; echo "age:" . $_POST["age_post"] . $ENTER; ?>
//_FILE echo "Error: " . $_FILES["file"]["error"] . "<br>"; echo "Upload: " . $_FILES["file"]["name"] . "<br>"; echo "Type: " . $_FILES["file"]["type"] . "<br>"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br>"; echo "Stored in: " . $_FILES["file"]["tmp_name"];
<?php setcookie("user", "zxm"); ?>
//cookie if (isset($_COOKIE['user'])) echo "Welcome " . $_COOKIE['user'] . "!<br>"; else echo "Welcome guest!<br>";
<?php session_start(); $_SESSION['id'] = "100"; ?>
//session if(isset($_SESSION['id'])) echo "session id: " . $_SESSION['id'] . $ENTER; else echo "without session" . $ENTER; ?>
//request echo "request: " . $_REQUEST['name_get'] . "!<br>"; ?>
"; //__GLOBALS[] $var1 = 5; $var2 = 10; print $GLOBALS['var1'] . $ENTER ; print $GLOBALS['var2'] . $ENTER ; //_SERVER print "SERVER_ADDR:" . $_SERVER['SERVER_ADDR'] . $ENTER; //_GET echo "name:" . $_GET["name_get"] . $ENTER ; echo "age:" . $_GET["age_get"] . $ENTER; //_POST echo "name:" . $_POST["name_post"] . $ENTER ; echo "age:" . $_POST["age_post"] . $ENTER; //_FILE echo "Error: " . $_FILES["file"]["error"] . $ENTER; echo "Upload: " . $_FILES["file"]["name"] . $ENTER; echo "Type: " . $_FILES["file"]["type"] . $ENTER; echo "Size: " . ($_FILES["file"]["size"] / 1024) . $ENTER; echo "Stored in: " . $_FILES["file"]["tmp_name"] . $ENTER; //cookie if (isset($_COOKIE['user'])) echo "Welcome: " . $_COOKIE['user'] . "!
"; else echo "Welcome guest!
"; //session if(isset($_SESSION['id'])) echo "session id: " . $_SESSION['id'] . $ENTER; else echo "without session" . $ENTER; //request echo "request: " . $_REQUEST['name_get'] . "!<br>"; ?>