수퍼글로벌 변수란 무엇인가요?
PHP에서 사전 정의된 많은 변수는 "수퍼글로벌"입니다. 즉, 스크립트의 전체 범위에서 사용할 수 있습니다. 전역 $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>
위 내용은 PHP - 전역변수와 PHP 내용을 포함한 슈퍼 전역변수_스터디노트를 소개한 내용입니다. PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되었으면 좋겠습니다.