Maison  >  Article  >  développement back-end  >  PHP——超全局变量_学习笔记 php application 全局变量 php 全局静态变量 php全局变量赋

PHP——超全局变量_学习笔记 php application 全局变量 php 全局静态变量 php全局变量赋

WBOY
WBOYoriginal
2016-07-29 08:53:451687parcourir

什么是超全局变量

PHP 中的许多预定义变量都是“超全局的”,这意味着它们在一个脚本的全部作用域中都可用。在函数或方法中无需执行 global $variable; 就可以访问它们。

<code><span>$_SERVER</span><span>//查看服务器信息</span><span>$_GET</span><span>//地址栏参数</span><span>$_POST</span><span>//表单提交的值</span><span>$_REQUEST</span><span>//接受$_GET或$_POST的值</span><span>$_FILES</span><span>//文件上传</span><span>$_COOKIE</span><span>//跟踪用户状态</span><span>$_SESSION</span><span>//跟踪用户状态</span><span>$GLOBALS</span><span>//获取所有全局变量的值</span></code>

$_SERVER:
可以查看服务器的信息,里面保存关于报头、路径和脚本位置的信息。
下面打印出来看下:

<code><span><span><?php </span>
print_r(<span>$_SERVER</span>);
<span>?></span></span></span></code>

结果如下:

<code>Array
(
    [HTTP_HOST]<span> =></span> localhost
    [HTTP_CONNECTION]<span> =></span> keep-alive
    [HTTP_CACHE_CONTROL]<span> =></span> max-age=<span>0</span>
    [HTTP_ACCEPT]<span> =></span> text<span>/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/</span>*;q=<span>0.8</span>
    [HTTP_UPGRADE_INSECURE_REQUESTS]<span> =></span><span>1</span>
    [HTTP_USER_AGENT]<span> =></span> Mozilla/<span>5.0</span> (Windows NT <span>6.1</span>; WOW64) AppleWebKit/<span>537.36</span> (KHTML, like Gecko) Chrome/<span>48.0</span><span>.2564</span><span>.116</span> UBrowser/<span>5.6</span><span>.11466</span><span>.7</span> Safari/<span>537.36</span>
    [HTTP_REFERER]<span> =></span><span>http</span>:<span>//</span>localhost<span>/PHP/php7/</span>
    [HTTP_ACCEPT_ENCODING]<span> =></span> gzip, deflate
    [HTTP_ACCEPT_LANGUAGE]<span> =></span> zh-CN,zh;q=<span>0.8</span>
    [PATH]<span> =></span><span>C</span>:\Windows\system32;<span>C</span>:\Windows;<span>C</span>:\Windows\System32\Wbem;<span>C</span>:\Windows\System32\WindowsPowerShell\v1<span>.0</span>\;
    [SystemRoot]<span> =></span><span>C</span>:\Windows
    [COMSPEC]<span> =></span><span>C</span>:\Windows\system32\cmd.exe
    [PATHEXT]<span> =></span> .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
    [WINDIR]<span> =></span><span>C</span>:\Windows
    [SERVER_SIGNATURE]<span> =></span> <address>Apache/<span>2.4</span><span>.9</span> (Win64) PHP/<span>5.5</span><span>.12</span> Server at localhost Port <span>80</span>
</address>

    [SERVER_SOFTWARE]<span> =></span> Apache/<span>2.4</span><span>.9</span> (Win64) PHP/<span>5.5</span><span>.12</span>
    [SERVER_NAME]<span> =></span> localhost
    [SERVER_ADDR]<span> =></span> ::<span>1</span>
    [SERVER_PORT]<span> =></span><span>80</span>
    [REMOTE_ADDR]<span> =></span> ::<span>1</span>
    [DOCUMENT_ROOT]<span> =></span><span>D</span>:<span>/www/</span>
    [REQUEST_SCHEME]<span> =></span> http
    [CONTEXT_PREFIX]<span> =></span>    [CONTEXT_DOCUMENT_ROOT]<span> =></span><span>D</span>:<span>/www/</span>
    [SERVER_ADMIN]<span> =></span> admin<span>@example</span>.com
    [SCRIPT_FILENAME]<span> =></span><span>D</span>:/www/PHP/php7/demo.php
    [REMOTE_PORT]<span> =></span><span>52683</span>
    [GATEWAY_INTERFACE]<span> =></span> CGI/<span>1.1</span>
    [SERVER_PROTOCOL]<span> =></span> HTTP/<span>1.1</span>
    [REQUEST_METHOD]<span> =></span> GET
    [QUERY_STRING]<span> =></span>    [REQUEST_URI]<span> =></span> /PHP/php7/demo.php
    [SCRIPT_NAME]<span> =></span> /PHP/php7/demo.php
    [PHP_SELF]<span> =></span> /PHP/php7/demo.php
    [REQUEST_TIME_FLOAT]<span> =></span><span>1460548562.994</span>
    [REQUEST_TIME]<span> =></span><span>1460548562</span>
)</code>
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了PHP——超全局变量_学习笔记,包括了全局变量,php方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn