PHP Tutorials - Herong's Tutorial Examples - v5.17, by Herong Yang
Operating System Information in $_SERVER
This section provides a tutorial example on how to dump operating system information stored in the $_SERVER array.
To help us understand how predefined variables, $_GET, $_POST, $_COOKIE, $_REQUEST, and $_SERVER, work, I wrote the following tutorial example script:
<?php # HttpRequestDetails.php #- Copyright 2003 (c) HerongYang.com. All Rights Reserved. # print "<pre>\n"; print "\nContents of \$_GET:\n"; foreach ($_GET as $k => $v) { print " $k = $v\n"; } # print "\nContents of \$_POST:\n"; foreach ($_POST as $k => $v) { print " $k = $v\n"; } # print "\nContents of \$_COOKIE:\n"; foreach ($_COOKIE as $k => $v) { print " $k = $v\n"; } # print "\nContents of \$_REQUEST:\n"; foreach ($_REQUEST as $k => $v) { print " $k = $v\n"; } # print "\nContents of \$_SERVER:\n"; foreach ($_SERVER as $k => $v) { print " $k = $v\n"; } print "</pre>\n"; ?>
If you run this example script standalone without using any Web server, you should get:
<pre> Contents of $_GET: Contents of $_POST: Contents of $_COOKIE: Contents of $_REQUEST: Contents of $_SERVER: ALLUSERSPROFILE = C:\ProgramData CommonProgramFiles = C:\Program Files\Common Files CommonProgramFiles(x86) = C:\Program Files (x86)\Common Files CommonProgramW6432 = C:\Program Files\Common Files ComSpec = C:\windows\system32\cmd.exe configsetroot = C:\windows\ConfigSetRoot FP_NO_HOST_CHECK = NO ProgramData = C:\ProgramData ProgramFiles = C:\Program Files ProgramFiles(x86) = C:\Program Files (x86) ProgramW6432 = C:\Program Files PROMPT = $P$G ...... </pre>
Note that $_GET, $_POST, $_COOKIE, and $_REQUEST are all empty, because we executed the script without any HTTP request. $_SERVER contains only information gathered from the operating system.
Table of Contents
Introduction and Installation of PHP
PHP Data Types and Data Literals
Variables, References, and Constants
Expressions, Operations and Type Conversions
Conditional Statements - "if" and "switch"
Loop Statements - "while", "for", and "do ... while"
Function Declaration, Arguments, and Return Values
Interface with Operating System
Introduction of Class and Object
Integrating PHP with Apache Web Server
►Retrieving Information from HTTP Requests
Predefined Variables Related to HTTP Requests
►Operating System Information in $_SERVER
Web Server Information in $_SERVER
Information in $_GET and $_REQUEST
Registering $_REQUEST Keys as Global Variables
Creating and Managing Sessions in PHP Scripts
Sending and Receiving Cookies in PHP Scripts
Controlling HTTP Response Header Lines in PHP Scripts
MySQL Server Connection and Access Functions
Functions to Manage Directories, Files and Images
SOAP Extension Function and Calling Web Services
SOAP Server Functions and Examples
Localization Overview of Web Applications
Using Non-ASCII Characters in HTML Documents
Using Non-ASCII Characters as PHP Script String Literals
Receiving Non-ASCII Characters from Input Forms
"mbstring" Extension and Non-ASCII Encoding Management
Managing Non-ASCII Character Strings with MySQL Servers
Parsing and Managing HTML Documents
Configuring and Sending Out Emails
Managing PHP Engine and Modules on macOS