<tbody id="i6oek"><cite id="i6oek"></cite></tbody>
  • <fieldset id="i6oek"><tbody id="i6oek"></tbody></fieldset>
    <rt id="i6oek"></rt>
  • \n\n
    \">\nName: \n\n<\/form>\n\n<?php \n$name = $_REQUEST['fname']; \necho $name; \n?>\n\n<\/body>\n<\/html><\/pre>\n<\/div>\n

    PHP $_POST<\/strong><\/p>\n

    PHP $_POST 被廣泛應(yīng)用于收集表單數(shù)據(jù),在HTML form標(biāo)簽的指定該屬性:\"method=\"post\"。<\/p>\n

    以下實(shí)例顯示了一個(gè)輸入字段(input)及提交按鈕(submit)的表單(form)。 當(dāng)用戶通過點(diǎn)擊 \"Submit\" 按鈕提交表單數(shù)據(jù)時(shí), 表單數(shù)據(jù)將發(fā)送至標(biāo)簽中 action 屬性中指定的腳本文件。 在這個(gè)實(shí)例中,我們指定文件來(lái)處理表單數(shù)據(jù)。如果你希望其他的PHP文件來(lái)處理該數(shù)據(jù),你可以修改該指定的腳本文件名。 然后,我們可以使用超級(jí)全局變量 $_POST 來(lái)收集表單中的 input 字段數(shù)據(jù):<\/p>\n

    \n
    \n\n
    

    国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

    \n\n\">\nName: \n\n<\/form>\n\n<?php \n$name = $_POST['fname']; \necho $name; \n?>\n\n<\/body>\n<\/html><\/pre>\n<\/div>\n

    PHP $_GET<\/strong><\/p>\n

    PHP $_GET 同樣被廣泛應(yīng)用于收集表單數(shù)據(jù),在HTML form標(biāo)簽的指定該屬性:\"method=\"get\"。<\/p>\n

    $_GET 也可以收集URL中發(fā)送的數(shù)據(jù)。<\/p>\n

    假定我們有一個(gè)包含參數(shù)的超鏈接HTML頁(yè)面:<\/p>\n

    \n
    \n\n\n\nTest $GET<\/a>\n\n<\/body>\n<\/html><\/pre>\n<\/div>\n

    當(dāng)用戶點(diǎn)擊鏈接 \"Test $GET\", 參數(shù) \"subject\" 和 \"web\" 將發(fā)送至\"test_get.php\",你可以在 \"test_get.php\" 文件中使用 $_GET 變量來(lái)獲取這些數(shù)據(jù)。<\/p>\n

    以下實(shí)例顯示了 \"test_get.php\" 文件的代碼:<\/p>\n

    \n
    \n\n\n\n<?php \necho \"Study \" . $_GET['subject'] . \" at \" . $_GET['web'];\n?>\n\n<\/body>\n<\/html><\/pre>\n<\/div>\n

    提示:<\/strong>?你如果想學(xué)習(xí)更多關(guān)于 $_POST 和 $_GET 的知識(shí),請(qǐng)?jiān)L問我們的?PHP 表單?章節(jié)。<\/p>\n

    以上就是小編為大家?guī)?lái)的全面了解PHP中的全局變量全部?jī)?nèi)容了,希望大家多多支持腳本之家~<\/p>\n\n"}

    Home Backend Development PHP Tutorial Comprehensive understanding of global variables in PHP_php examples

    Comprehensive understanding of global variables in PHP_php examples

    Jul 06, 2016 pm 01:32 PM
    php global variables

    Several superglobals are predefined in PHP, which means that they are available in the entire scope of a script. You can use it in functions and classes without special instructions.

    PHP super global variable list:

    ?$GLOBALS
    ?$_SERVER
    ?$_REQUEST
    ?$_POST
    ?$_GET
    ?$_FILES
    ?$_ENV
    ?$_COOKIE
    ?$_SESSION

    In this chapter we will explain several commonly used super global variables, and we will introduce the remaining variables in the next few chapters.

    PHP $GLOBAL

    $GLOBAL is a super global variable group of PHP, which can be accessed in the entire scope of a PHP script.

    $GLOBAL is a global combined array containing all variables. The name of the variable is the key of the array.

    The following example shows how to use the super global variable $GLOBAL:

    <&#63;php 
    $x = 75; 
    $y = 25;
     
    function addition() 
    { 
    $GLOBALS['z'] = $GLOBALS['x'] + $GLOBALS['y']; 
    }
     
    addition(); 
    echo $z; 
    &#63;>

    In the above example, z is a super global variable in the $GLOBALS array, which can also be accessed outside the function.

    PHP $_SERVER

    $_SERVER is an array containing information such as header, path, and script locations. The items in this array are created by the web server. There is no guarantee that every server will offer all items; servers may ignore some, or serve items not listed here.

    The following example shows how to use the elements in $_SERVER:

    <&#63;php 
    echo $_SERVER['PHP_SELF'];
    echo "<br>";
    echo $_SERVER['SERVER_NAME'];
    echo "<br>";
    echo $_SERVER['HTTP_HOST'];
    echo "<br>";
    echo $_SERVER['HTTP_REFERER'];
    echo "<br>";
    echo $_SERVER['HTTP_USER_AGENT'];
    echo "<br>";
    echo $_SERVER['SCRIPT_NAME'];
    &#63;>

    The following table lists the important elements in all $_SERVER variables:

    元素/代碼 描述
    $_SERVER['PHP_SELF'] 當(dāng)前執(zhí)行腳本的文件名,與 document root 有關(guān)。例如,在地址為 http://example.com/test.php/foo.bar 的腳本中使用 $_SERVER['PHP_SELF'] 將得到 /test.php/foo.bar。__FILE__ 常量包含當(dāng)前(例如包含)文件的完整路徑和文件名。 從 PHP 4.3.0 版本開始,如果 PHP 以命令行模式運(yùn)行,這個(gè)變量將包含腳本名。之前的版本該變量不可用。
    $_SERVER['GATEWAY_INTERFACE'] 服務(wù)器使用的 CGI 規(guī)范的版本;例如,"CGI/1.1"。
    $_SERVER['SERVER_ADDR'] 當(dāng)前運(yùn)行腳本所在的服務(wù)器的 IP 地址。
    $_SERVER['SERVER_NAME'] 當(dāng)前運(yùn)行腳本所在的服務(wù)器的主機(jī)名。如果腳本運(yùn)行于虛擬主機(jī)中,該名稱是由那個(gè)虛擬主機(jī)所設(shè)置的值決定。(如: www.manongjc.com)
    $_SERVER['SERVER_SOFTWARE'] 服務(wù)器標(biāo)識(shí)字符串,在響應(yīng)請(qǐng)求時(shí)的頭信息中給出。 (如:Apache/2.2.24)
    $_SERVER['SERVER_PROTOCOL'] 請(qǐng)求頁(yè)面時(shí)通信協(xié)議的名稱和版本。例如,"HTTP/1.0"。
    $_SERVER['REQUEST_METHOD'] 訪問頁(yè)面使用的請(qǐng)求方法;例如,"GET", "HEAD","POST","PUT"。
    $_SERVER['REQUEST_TIME'] 請(qǐng)求開始時(shí)的時(shí)間戳。從 PHP 5.1.0 起可用。 (如:1377687496)
    $_SERVER['QUERY_STRING'] query string(查詢字符串),如果有的話,通過它進(jìn)行頁(yè)面訪問。
    $_SERVER['HTTP_ACCEPT'] 當(dāng)前請(qǐng)求頭中 Accept: 項(xiàng)的內(nèi)容,如果存在的話。
    $_SERVER['HTTP_ACCEPT_CHARSET'] 當(dāng)前請(qǐng)求頭中 Accept-Charset: 項(xiàng)的內(nèi)容,如果存在的話。例如:"iso-8859-1,*,utf-8"。
    $_SERVER['HTTP_HOST'] 當(dāng)前請(qǐng)求頭中 Host: 項(xiàng)的內(nèi)容,如果存在的話。
    $_SERVER['HTTP_REFERER'] 引導(dǎo)用戶代理到當(dāng)前頁(yè)的前一頁(yè)的地址(如果存在)。由 user agent 設(shè)置決定。并不是所有的用戶代理都會(huì)設(shè)置該項(xiàng),有的還提供了修改 HTTP_REFERER 的功能。簡(jiǎn)言之,該值并不可信。)
    $_SERVER['HTTPS'] 如果腳本是通過 HTTPS 協(xié)議被訪問,則被設(shè)為一個(gè)非空的值。
    $_SERVER['REMOTE_ADDR'] 瀏覽當(dāng)前頁(yè)面的用戶的 IP 地址。
    $_SERVER['REMOTE_HOST'] 瀏覽當(dāng)前頁(yè)面的用戶的主機(jī)名。DNS 反向解析不依賴于用戶的 REMOTE_ADDR。
    $_SERVER['REMOTE_PORT'] 用戶機(jī)器上連接到 Web 服務(wù)器所使用的端口號(hào)。
    $_SERVER['SCRIPT_FILENAME'] 當(dāng)前執(zhí)行腳本的絕對(duì)路徑。
    $_SERVER['SERVER_ADMIN'] 該值指明了 Apache 服務(wù)器配置文件中的 SERVER_ADMIN 參數(shù)。如果腳本運(yùn)行在一個(gè)虛擬主機(jī)上,則該值是那個(gè)虛擬主機(jī)的值。(如:someone@manongjc.com)
    $_SERVER['SERVER_PORT'] Web 服務(wù)器使用的端口。默認(rèn)值為 "80"。如果使用 SSL 安全連接,則這個(gè)值為用戶設(shè)置的 HTTP 端口。
    $_SERVER['SERVER_SIGNATURE'] 包含了服務(wù)器版本和虛擬主機(jī)名的字符串。
    $_SERVER['PATH_TRANSLATED'] 當(dāng)前腳本所在文件系統(tǒng)(非文檔根目錄)的基本路徑。這是在服務(wù)器進(jìn)行虛擬到真實(shí)路徑的映像后的結(jié)果。
    $_SERVER['SCRIPT_NAME'] 包含當(dāng)前腳本的路徑。這在頁(yè)面需要指向自己時(shí)非常有用。__FILE__ 常量包含當(dāng)前腳本(例如包含文件)的完整路徑和文件名。
    $_SERVER['SCRIPT_URI'] URI 用來(lái)指定要訪問的頁(yè)面。例如 "/index.html"。


    PHP $_REQUEST

    PHP $_REQUEST 用于收集HTML表單提交的數(shù)據(jù)。

    以下實(shí)例顯示了一個(gè)輸入字段(input)及提交按鈕(submit)的表單(form)。 當(dāng)用戶通過點(diǎn)擊 "Submit" 按鈕提交表單數(shù)據(jù)時(shí), 表單數(shù)據(jù)將發(fā)送至標(biāo)簽中 action 屬性中指定的腳本文件。 在這個(gè)實(shí)例中,我們指定文件來(lái)處理表單數(shù)據(jù)。如果你希望其他的PHP文件來(lái)處理該數(shù)據(jù),你可以修改該指定的腳本文件名。 然后,我們可以使用超級(jí)全局變量 $_REQUEST 來(lái)收集表單中的 input 字段數(shù)據(jù):

    <html>
    <body>
    
    <form method="post" action="<&#63;php echo $_SERVER['PHP_SELF'];&#63;>">
    Name: <input type="text" name="fname">
    <input type="submit">
    </form>
    
    <&#63;php 
    $name = $_REQUEST['fname']; 
    echo $name; 
    &#63;>
    
    </body>
    </html>

    PHP $_POST

    PHP $_POST 被廣泛應(yīng)用于收集表單數(shù)據(jù),在HTML form標(biāo)簽的指定該屬性:"method="post"。

    以下實(shí)例顯示了一個(gè)輸入字段(input)及提交按鈕(submit)的表單(form)。 當(dāng)用戶通過點(diǎn)擊 "Submit" 按鈕提交表單數(shù)據(jù)時(shí), 表單數(shù)據(jù)將發(fā)送至標(biāo)簽中 action 屬性中指定的腳本文件。 在這個(gè)實(shí)例中,我們指定文件來(lái)處理表單數(shù)據(jù)。如果你希望其他的PHP文件來(lái)處理該數(shù)據(jù),你可以修改該指定的腳本文件名。 然后,我們可以使用超級(jí)全局變量 $_POST 來(lái)收集表單中的 input 字段數(shù)據(jù):

    <html>
    <body>
    
    <form method="post" action="<&#63;php echo $_SERVER['PHP_SELF'];&#63;>">
    Name: <input type="text" name="fname">
    <input type="submit">
    </form>
    
    <&#63;php 
    $name = $_POST['fname']; 
    echo $name; 
    &#63;>
    
    </body>
    </html>

    PHP $_GET

    PHP $_GET 同樣被廣泛應(yīng)用于收集表單數(shù)據(jù),在HTML form標(biāo)簽的指定該屬性:"method="get"。

    $_GET 也可以收集URL中發(fā)送的數(shù)據(jù)。

    假定我們有一個(gè)包含參數(shù)的超鏈接HTML頁(yè)面:

    <html>
    <body>
    
    <a href="test_get.php&#63;subject=PHP&web=manongjc.com">Test $GET</a>
    
    </body>
    </html>

    當(dāng)用戶點(diǎn)擊鏈接 "Test $GET", 參數(shù) "subject" 和 "web" 將發(fā)送至"test_get.php",你可以在 "test_get.php" 文件中使用 $_GET 變量來(lái)獲取這些數(shù)據(jù)。

    以下實(shí)例顯示了 "test_get.php" 文件的代碼:

    <html>
    <body>
    
    <&#63;php 
    echo "Study " . $_GET['subject'] . " at " . $_GET['web'];
    &#63;>
    
    </body>
    </html>

    提示:?你如果想學(xué)習(xí)更多關(guān)于 $_POST 和 $_GET 的知識(shí),請(qǐng)?jiān)L問我們的?PHP 表單?章節(jié)。

    以上就是小編為大家?guī)?lái)的全面了解PHP中的全局變量全部?jī)?nèi)容了,希望大家多多支持腳本之家~

    Statement of this Website
    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

    Hot AI Tools

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    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.

    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

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    How to get the current session ID in PHP? How to get the current session ID in PHP? Jul 13, 2025 am 03:02 AM

    The method to get the current session ID in PHP is to use the session_id() function, but you must call session_start() to successfully obtain it. 1. Call session_start() to start the session; 2. Use session_id() to read the session ID and output a string similar to abc123def456ghi789; 3. If the return is empty, check whether session_start() is missing, whether the user accesses for the first time, or whether the session is destroyed; 4. The session ID can be used for logging, security verification and cross-request communication, but security needs to be paid attention to. Make sure that the session is correctly enabled and the ID can be obtained successfully.

    PHP get substring from a string PHP get substring from a string Jul 13, 2025 am 02:59 AM

    To extract substrings from PHP strings, you can use the substr() function, which is syntax substr(string$string,int$start,?int$length=null), and if the length is not specified, it will be intercepted to the end; when processing multi-byte characters such as Chinese, you should use the mb_substr() function to avoid garbled code; if you need to intercept the string according to a specific separator, you can use exploit() or combine strpos() and substr() to implement it, such as extracting file name extensions or domain names.

    How do you perform unit testing for php code? How do you perform unit testing for php code? Jul 13, 2025 am 02:54 AM

    UnittestinginPHPinvolvesverifyingindividualcodeunitslikefunctionsormethodstocatchbugsearlyandensurereliablerefactoring.1)SetupPHPUnitviaComposer,createatestdirectory,andconfigureautoloadandphpunit.xml.2)Writetestcasesfollowingthearrange-act-assertpat

    How to split a string into an array in PHP How to split a string into an array in PHP Jul 13, 2025 am 02:59 AM

    In PHP, the most common method is to split the string into an array using the exploit() function. This function divides the string into multiple parts through the specified delimiter and returns an array. The syntax is exploit(separator, string, limit), where separator is the separator, string is the original string, and limit is an optional parameter to control the maximum number of segments. For example $str="apple,banana,orange";$arr=explode(",",$str); The result is ["apple","bana

    JavaScript Data Types: Primitive vs Reference JavaScript Data Types: Primitive vs Reference Jul 13, 2025 am 02:43 AM

    JavaScript data types are divided into primitive types and reference types. Primitive types include string, number, boolean, null, undefined, and symbol. The values are immutable and copies are copied when assigning values, so they do not affect each other; reference types such as objects, arrays and functions store memory addresses, and variables pointing to the same object will affect each other. Typeof and instanceof can be used to determine types, but pay attention to the historical issues of typeofnull. Understanding these two types of differences can help write more stable and reliable code.

    Using std::chrono in C Using std::chrono in C Jul 15, 2025 am 01:30 AM

    std::chrono is used in C to process time, including obtaining the current time, measuring execution time, operation time point and duration, and formatting analysis time. 1. Use std::chrono::system_clock::now() to obtain the current time, which can be converted into a readable string, but the system clock may not be monotonous; 2. Use std::chrono::steady_clock to measure the execution time to ensure monotony, and convert it into milliseconds, seconds and other units through duration_cast; 3. Time point (time_point) and duration (duration) can be interoperable, but attention should be paid to unit compatibility and clock epoch (epoch)

    How to pass a session variable to another page in PHP? How to pass a session variable to another page in PHP? Jul 13, 2025 am 02:39 AM

    In PHP, to pass a session variable to another page, the key is to start the session correctly and use the same $_SESSION key name. 1. Before using session variables for each page, it must be called session_start() and placed in the front of the script; 2. Set session variables such as $_SESSION['username']='JohnDoe' on the first page; 3. After calling session_start() on another page, access the variables through the same key name; 4. Make sure that session_start() is called on each page, avoid outputting content in advance, and check that the session storage path on the server is writable; 5. Use ses

    PHP header location not working after include PHP header location not working after include Jul 13, 2025 am 02:08 AM

    When encountering the problem that header('Location:...') does not work, the common reasons and solutions are as follows: 1. There is output in advance, causing the header to fail. The solution is to ensure that there is no output before the jump, including spaces, HTML or echo; 2. There is excess output or UTF-8 BOM characters in the include or require file. The file encoding should be checked and saved as "UTF-8 BOM-free"; 3. It is recommended to use ob_start() to turn on the output buffer before the jump, and cooperate with ob_end_flush() to delay the output; 4. After the jump, be sure to add exit to prevent subsequent code execution; 5. Make sure that the header() function call is before all outputs.

    See all articles