虽然这个几个比较常见,但是未必每个人都会用,我就简单整理一下….

$_SERVER

var_dump出的效果,说一个Array,你应该知道怎么用吧,其中的PHP_SELF,USER_AGENT等相信对你会有用

array
  'HTTP_USER_AGENT' => string 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_5; en-us) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.2 Safari/525.20.1' (length=125)
  'HTTP_CACHE_CONTROL' => string 'max-age=0' (length=9)
  'HTTP_ACCEPT' => string 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5' (length=99)
  'HTTP_ACCEPT_LANGUAGE' => string 'en-us' (length=5)
  'HTTP_ACCEPT_ENCODING' => string 'gzip, deflate' (length=13)
  'HTTP_COOKIE' => string 'ECS[user_id]=1; ECS[username]=admin; ECS[email]=webmastor%40yourdomain.com; ECS[visit_times]=2; uchome_auth=17720Ag3apHxh%2BuqAnNG8K5qnVoihVoPyRr%2FFlsyF2tXb2eNCHfN47eFyCvT0qgBtm6q1cWCMQL5FvsmoVgA; uchome_loginuser=gxbsst; mpH_cookietime=2592000; mpH_loginuser=gxbsst; mpH_activationauth=5085X8lEKxwsND0uhjEwcl1HBxdSgnky%2B8HAS%2BXMVSMCbac' (length=339)
  'HTTP_CONNECTION' => string 'keep-alive' (length=10)
  'HTTP_HOST' => string 'localhost' (length=9)
  'PATH' => string '/usr/bin:/bin:/usr/sbin:/sbin' (length=29)
  'SERVER_SIGNATURE' => string '' (length=0)
  'SERVER_SOFTWARE' => string 'Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.7l DAV/2 PHP/5.2.6 mod_fastcgi/2.4.2' (length=82)
  'SERVER_NAME' => string 'localhost' (length=9)
  'SERVER_ADDR' => string '::1' (length=3)
  'SERVER_PORT' => string '80' (length=2)
  'REMOTE_ADDR' => string '::1' (length=3)
  'DOCUMENT_ROOT' => string '/Users/weston/projects/linyufang.net' (length=36)
  'SERVER_ADMIN' => string 'you@example.com' (length=15)
  'SCRIPT_FILENAME' => string '/Users/weston/projects/linyufang.net/form_data.php' (length=50)
  'REMOTE_PORT' => string '59715' (length=5)
  'GATEWAY_INTERFACE' => string 'CGI/1.1' (length=7)
  'SERVER_PROTOCOL' => string 'HTTP/1.1' (length=8)
  'REQUEST_METHOD' => string 'GET' (length=3)
  'QUERY_STRING' => string '' (length=0)
  'REQUEST_URI' => string '/form_data.php' (length=14)
  'SCRIPT_NAME' => string '/form_data.php' (length=14)
  'PHP_SELF' => string '/form_data.php' (length=14)
  'REQUEST_TIME' => int 1223026388
  'argv' => 
    array
      empty
  'argc' => int 0

$_REQUEST

array
  'ECS' => 
    array
      'user_id' => string '1' (length=1)
      'username' => string 'admin' (length=5)
      'email' => string 'webmastor@yourdomain.com' (length=24)
      'visit_times' => string '2' (length=1)
  'uchome_auth' => string '17720Ag3apHxh+uqAnNG8K5qnVoihVoPyRr/FlsyF2tXb2eNCHfN47eFyCvT0qgBtm6q1cWCMQL5FvsmoVgA' (length=84)
  'uchome_loginuser' => string 'gxbsst' (length=6)
  'mpH_cookietime' => string '2592000' (length=7)
  'mpH_loginuser' => string 'gxbsst' (length=6)
  'mpH_activationauth' => string '5085X8lEKxwsND0uhjEwcl1HBxdSgnky+8HAS+XMVSMCbac' (length=47)

$_COOKIE

array
  'ECS' => 
    array
      'user_id' => string '1' (length=1)
      'username' => string 'admin' (length=5)
      'email' => string 'webmastor@yourdomain.com' (length=24)
      'visit_times' => string '2' (length=1)
  'uchome_auth' => string '17720Ag3apHxh+uqAnNG8K5qnVoihVoPyRr/FlsyF2tXb2eNCHfN47eFyCvT0qgBtm6q1cWCMQL5FvsmoVgA' (length=84)
  'uchome_loginuser' => string 'gxbsst' (length=6)
  'mpH_cookietime' => string '2592000' (length=7)
  'mpH_loginuser' => string 'gxbsst' (length=6)
  'mpH_activationauth' => string '5085X8lEKxwsND0uhjEwcl1HBxdSgnky+8HAS+XMVSMCbac' (length=47)

$_ENV

array
  'PATH' => string '/usr/bin:/bin:/usr/sbin:/sbin' (length=29)

当然还要$_GET,$_SESSION,$_COOKIE其实这些都可以在phpinfo看到的….
btw:要深入了解,相信PERL的CGI编程那本书对你会有用处…

*当然其他Web开发语言都有类似变量….

转载请注明:韦旭红的点点滴滴 » PHP 几个有用的变量