首頁 > 後端開發 > php教程 > PHP—超全域變數_學習筆記 php application 全域變數 php 全域靜態變數 php全域變數賦

PHP—超全域變數_學習筆記 php application 全域變數 php 全域靜態變數 php全域變數賦

WBOY
發布: 2016-07-29 08:53:45
原創
1712 人瀏覽過

什麼是超全域變數

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></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教學有興趣的朋友有幫助。

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板