spacer
Web Development Tutorials PHP Tutorials
 Developer Newsletter

Tutorials
AJAX
ASP
CGI & Perl
CSS
Flash
HTML
Illustrator
Java
JavaScript
Linux
MySQL
PHP
Photoshop
Python
Wireless
XML
Miscellaneous


Scripts Directory
AJAX Scripts
ASP Scripts
ASP.NET Scripts
CGI & Perl Scripts
Flash Scripts
Java Scripts
JavaScript Scripts
PHP Scripts
Python Scripts
Remotely Hosted Scripts
Tools & Utilities Scripts
XML Scripts

Web Hosting Directory
ASP.NET
Budget
Dedicated Servers
Ecommerce
Linux
Resellers
Shared
Small Business
Windows

Developer Manuals
Learn HTML
Learn PHP
Learn CSS
Learn AJAX
Learn JavaScript
Learn Pear
Free White Papers

Developer Resources
Developer Tools
Developer Content
Survey Software
Dedicated Servers




Introduction to PHP Programming

By PHP Catalyst
2007-11-19


Variables in PHP

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.



Tutorial Pages:
» What can I do with PHP?
» Popoular Features of PHP
» Basics of PHP
» Variables in PHP
» Data Types in PHP
» Expressions and Operators
» Control Structures in PHP
» Functions in PHP
» Declaring Functions in PHP
» Scope of a Variable
» Built-in Functions in PHP
» Handling Strings in PHP
» Printing Strings in PHP
» String Comparisons in PHP
» Manipulating Strings in PHP
» Arrays in PHP
» Types of Arrays in PHP
» Creating Arrays in PHP
» Array Operations in PHP


 | Bookmark Print |   Write For Us
Related Tutorials:
» Web Database Access from Desktop Applications
» CubeCart 3.0 Installation and Configuration
» PHP Site Search Made Easy
» Installing and Configuring Drupal 6.1
» Desktop Application Development with PHP-GTK
» Installing PHP on Windows



About the NetVisits, Inc Network | Write For Us | Advertise
Copyright ©2007 NetVisits, Inc Network. All Rights Reserved. Privacy Policy.
Visit other NetVisits, Inc. sites: