PHP Notes 6

PHP Notes 6 Lakshman Gupta  9:33 AM 10/8/2019
PHP Tutorial

<html>
....
_A_;
....
?>
The following example displays all the cookies releated with the visited site:
<?php
if (!$_COOKIE) { $_COOKIE = $HTTP_COOKIE_VARS; }
foreach ($_COOKIE as $ck => $val)
{ print "<dd>Cookie name: $ck; value: $val<br />\n"; }
?>
Examples:
· Webmail: store and use username.
· Weather Site: store the selected city in a cookie, and next time the site is visited, the weather of the
stored city is automatically displayed.
Built-in Variables
PHP has a number of built-in variables that give you access to your Web server's CGI environment,
form/cookie data and PHP internals. Here are some of the most useful variables:
PHP internal variables
The $GLOBALS and $PHP_SELF variables shown in the table below are specific to PHP:
Variable
Name
Description
$GLOBALS An associative array of all global variables. This is the only variable in PHP that is available
regardless of scope. You can access it anywhere without declaring it as a global first.
$PHP_SELF This is the current script, for example /~ssb/phpinfo.php3.
$_POST An associative array of POST variables.
$_GET An associative array of GET variables.
$_COOKIE An associative array of COOKIE variables.
$_SERVER An associative array of SERVER variables.
CGI / Web server provided variables
The variables listed below are derived from CGI protocols.
Variable Name Description
$DOCUMENT_ROOT Your Web server's base directory with user-visible files.
$REQUEST_METHOD The HTTP method used to access this page, for example GET or POST.
$REQUEST_URI Full local part of the request URL, including parameters.
$SCRIPT_FILENAME File name of the top-level page being executed.
$SCRIPT_NAME Local URI part of the page being executed.
$SERVER_NAME Domain name for the server.
$SERVER_PORT TCP port number the server runs on.
HTTP Request Variables
HTTP Request Variables are derived from their corresponding HTTP headers.
$REMOTE_ADDR IP address of the client (browser) machine
$HTTP_HOST Host name in the browser's "location" field.
$HTTP_USER_AGENT User agent (browser) being used.
$HTTP_REFERER URL of the referring page.