Introduction to PHP Programming
By PHP Catalyst2007-11-19
Variables
A variable is something that is subject to variation or likely to vary. In PHP variables are represented with a dollar sign before the variable name. For example $a, $b are variables. The variable name is case-sensitive and must always start with a character. So, $a and $A are different variable names. Some examples are:
<?php
$first_name = 'firstname'; //Valid
$last_name = 'lastname'; //Valid
$Middle_Name = 'middlename'; //Valid
echo "$firstname, $Middle_Name, $last_name";
$9Name = 'name'; //not valid. Variable name can not start with a number
?>
Predefined variables
PHP provides significant number of predefined variables, some of which are platform dependent, version specific, server specific.
Some of the widely used predefined variables are:
Server variables:
$_SERVER when used, offers information such as hostname, script name, location etc. When used, the information is obtained onto this array from the web server running PHP. However, as we read before, you may not be able to get all the information when this variable is used.
Widely used elements of $_SERVER are as mentioned below:
'PHP_SELF' refers to file name of the currently executed script. For instance if the URL is http://www.phpcatayst.com/examples/self.php then $_SERVER['PHP_SELF'] will refer to /examples/self.php
'argv' array of arguments passed to the script.
contains the number of command line parameters passed to the script
'SERVER_ADDR' the IP address of the server on which the current script is executing.
'SERVER_NAME' the hostname of the server on which the current script is executing.
'REQUEST_METHOD' request method which was used to access the page; i.e. 'GET', 'HEAD', 'POST', 'PUT'.
'QUERY_STRING' the query string, via which the page was accessed.
'DOCUMENT_ROOT' the document root directory under which the current script is executing. This information is obtained from server's configuration file.
'HTTP_ACCEPT' contents of the Accept: header from the current request, if there is one.
'HTTP_REFERER' the address of the page which referred to the current page.
'HTTPS' set to a non-empty value if the script was queried through the HTTPS protocol.
'REMOTE_ADDR' the IP address from which the user is viewing the current page.
'REQUEST_URI' the URI used to access the current page.
|
|||||||||
You might also want to check these out:
|
Link to This Tutorial Page!

