search
HomeBackend DevelopmentPHP TutorialExample explanation of predefined variables for PHP learning

下面小编就为大家分享一篇PHP学习之预定义变量(实例讲解),具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

超全局变量

超全局变量–超全局变量是全部作用域中始终可用的内置变量

$GLOBALS

一个包含了全部变量的全局组合数组。变量的名字就是数组的键。

<?php
function test() {
  $foo = "local variable";
  echo &#39;$foo in global scope: &#39; . $GLOBALS["foo"] . "\n";
  echo &#39;$foo in current scope: &#39; . $foo . "\n";
}
$foo = "Example content";
test();
?>
以上例程的输出类似于:
$foo in global scope: Example content
$foo in current scope: local variable

$_SERVER

<?PHP
echo "<pre class="brush:php;toolbar:false">";
var_dump($_SERVER);
output:
array (size=35)
 &#39;HTTP_HOST&#39; => string &#39;localhost&#39; (length=9)
 &#39;HTTP_CONNECTION&#39; => string &#39;keep-alive&#39; (length=10)
 &#39;HTTP_UPGRADE_INSECURE_REQUESTS&#39; => string &#39;1&#39; (length=1)
 &#39;HTTP_USER_AGENT&#39; => string &#39;Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.3538.400 QQBrowser/9.6.12501.400&#39; (length=153)
 &#39;HTTP_ACCEPT&#39; => string &#39;text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8&#39; (length=74)
 &#39;HTTP_REFERER&#39; => string &#39;http://localhost/test/&#39; (length=22)
 &#39;HTTP_ACCEPT_ENCODING&#39; => string &#39;gzip, deflate, sdch&#39; (length=19)
 &#39;HTTP_ACCEPT_LANGUAGE&#39; => string &#39;zh-CN,zh;q=0.8&#39; (length=14)
 &#39;PATH&#39; => string &#39;%APPCAN_PATH%;D:\Work\python2.7\;D:\Work\python2.7\Scripts;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;D:\wampserver\mysql\bin;D:\Work\JAVA\tomcat\bin;D:\Work\Mozilla Firefox\firefox.exe;D:\Work\phantomjs\bin;D:\Work\chormedriver;C:\WINDOWS\system32\config\systemprofile\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;D:\wampserver\php;C:\ProgramData\ComposerSetup\bi&#39;... (length=607)
 &#39;SystemRoot&#39; => string &#39;C:\WINDOWS&#39; (length=10)
 &#39;COMSPEC&#39; => string &#39;C:\WINDOWS\system32\cmd.exe&#39; (length=27)
 &#39;PATHEXT&#39; => string &#39;.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC&#39; (length=53)
 &#39;WINDIR&#39; => string &#39;C:\WINDOWS&#39; (length=10)
 &#39;SERVER_SIGNATURE&#39; => string &#39;&#39; (length=0)
 &#39;SERVER_SOFTWARE&#39; => string &#39;Apache/2.4.18 (Win64) OpenSSL/1.0.2g PHP/5.6.19&#39; (length=47)
 &#39;SERVER_NAME&#39; => string &#39;localhost&#39; (length=9)
 &#39;SERVER_ADDR&#39; => string &#39;::1&#39; (length=3)
 &#39;SERVER_PORT&#39; => string &#39;80&#39; (length=2)
 &#39;REMOTE_ADDR&#39; => string &#39;::1&#39; (length=3)
 &#39;DOCUMENT_ROOT&#39; => string &#39;D:/wampserver/www&#39; (length=17)
 &#39;REQUEST_SCHEME&#39; => string &#39;http&#39; (length=4)
 &#39;CONTEXT_PREFIX&#39; => string &#39;&#39; (length=0)
 &#39;CONTEXT_DOCUMENT_ROOT&#39; => string &#39;D:/wampserver/www&#39; (length=17)
 &#39;SERVER_ADMIN&#39; => string &#39;admin@example.com&#39; (length=17)
 &#39;SCRIPT_FILENAME&#39; => string &#39;D:/wampserver/www/test/$_SERVER.php&#39; (length=35)
 &#39;REMOTE_PORT&#39; => string &#39;57305&#39; (length=5)
 &#39;GATEWAY_INTERFACE&#39; => string &#39;CGI/1.1&#39; (length=7)
 &#39;SERVER_PROTOCOL&#39; => string &#39;HTTP/1.1&#39; (length=8)
 &#39;REQUEST_METHOD&#39; => string &#39;GET&#39; (length=3)
 &#39;QUERY_STRING&#39; => string &#39;&#39; (length=0)
 &#39;REQUEST_URI&#39; => string &#39;/test/$_SERVER.php&#39; (length=18)
 &#39;SCRIPT_NAME&#39; => string &#39;/test/$_SERVER.php&#39; (length=18)
 &#39;PHP_SELF&#39; => string &#39;/test/$_SERVER.php&#39; (length=18)
 &#39;REQUEST_TIME_FLOAT&#39; => float 1510122616.201
 &#39;REQUEST_TIME&#39; => int 1510122616

以上这篇PHP学习之预定义变量(实例讲解)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持php中文我网。

您可能感兴趣的文章:

PHP 获取某年第几周的开始日期和结束日期的实例讲解

PHP接口多继承及tarits实现多继承效果的方法_php技巧

thinkPHP5框架数据库连贯操作之cache()用法详解

The above is the detailed content of Example explanation of predefined variables for PHP learning. For more information, please follow other related articles on the PHP Chinese website!

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
How can you check if a PHP session has already started?How can you check if a PHP session has already started?Apr 30, 2025 am 12:20 AM

In PHP, you can use session_status() or session_id() to check whether the session has started. 1) Use the session_status() function. If PHP_SESSION_ACTIVE is returned, the session has been started. 2) Use the session_id() function, if a non-empty string is returned, the session has been started. Both methods can effectively check the session state, and choosing which method to use depends on the PHP version and personal preferences.

Describe a scenario where using sessions is essential in a web application.Describe a scenario where using sessions is essential in a web application.Apr 30, 2025 am 12:16 AM

Sessionsarevitalinwebapplications,especiallyfore-commerceplatforms.Theymaintainuserdataacrossrequests,crucialforshoppingcarts,authentication,andpersonalization.InFlask,sessionscanbeimplementedusingsimplecodetomanageuserloginsanddatapersistence.

How can you manage concurrent session access in PHP?How can you manage concurrent session access in PHP?Apr 30, 2025 am 12:11 AM

Managing concurrent session access in PHP can be done by the following methods: 1. Use the database to store session data, 2. Use Redis or Memcached, 3. Implement a session locking strategy. These methods help ensure data consistency and improve concurrency performance.

What are the limitations of using PHP sessions?What are the limitations of using PHP sessions?Apr 30, 2025 am 12:04 AM

PHPsessionshaveseverallimitations:1)Storageconstraintscanleadtoperformanceissues;2)Securityvulnerabilitieslikesessionfixationattacksexist;3)Scalabilityischallengingduetoserver-specificstorage;4)Sessionexpirationmanagementcanbeproblematic;5)Datapersis

Explain how load balancing affects session management and how to address it.Explain how load balancing affects session management and how to address it.Apr 29, 2025 am 12:42 AM

Load balancing affects session management, but can be resolved with session replication, session stickiness, and centralized session storage. 1. Session Replication Copy session data between servers. 2. Session stickiness directs user requests to the same server. 3. Centralized session storage uses independent servers such as Redis to store session data to ensure data sharing.

Explain the concept of session locking.Explain the concept of session locking.Apr 29, 2025 am 12:39 AM

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

Are there any alternatives to PHP sessions?Are there any alternatives to PHP sessions?Apr 29, 2025 am 12:36 AM

Alternatives to PHP sessions include Cookies, Token-based Authentication, Database-based Sessions, and Redis/Memcached. 1.Cookies manage sessions by storing data on the client, which is simple but low in security. 2.Token-based Authentication uses tokens to verify users, which is highly secure but requires additional logic. 3.Database-basedSessions stores data in the database, which has good scalability but may affect performance. 4. Redis/Memcached uses distributed cache to improve performance and scalability, but requires additional matching

Define the term 'session hijacking' in the context of PHP.Define the term 'session hijacking' in the context of PHP.Apr 29, 2025 am 12:33 AM

Sessionhijacking refers to an attacker impersonating a user by obtaining the user's sessionID. Prevention methods include: 1) encrypting communication using HTTPS; 2) verifying the source of the sessionID; 3) using a secure sessionID generation algorithm; 4) regularly updating the sessionID.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.