Home >Backend Development >PHP Tutorial >PHP - super global variables_study notes php application global variables php global static variables php global variable assignment

PHP - super global variables_study notes php application global variables php global static variables php global variable assignment

WBOY
WBOYOriginal
2016-07-29 08:53:451713browse

What are superglobal variables?

Many predefined variables in PHP are "superglobal", which means that they are available in the entire scope of a script. They can be accessed within a function or method without executing 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:
You can view server information, which holds information about headers, paths, and script locations.
Print it out below and take a look:

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

The results are as follows:

<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); }); });

The above introduces PHP - super global variables_study notes, including global variables and PHP content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn