You are on page 1of 7


Explanation: What is PHP? PHP stands for PHP Hypertext: Preprocess with that PHP standing for Personal Home Page [Tools]. PHP is an open-source language used primarily for dynamic web content and server-side applications. In an HTML document. PHP script (similar syntax to that of Perl or C ) is enclosed within special PHP tags. Because PHP is embedded within tags the author can jump between HTML and PHP (similar to ASP and Cold Fusion) instead of having to rely on heavy amounts of code to output HTML. And because PHP is executed on the server, the client cannot view the PHP code. PHP ofters excellent connectivity to many databases including My SQL. Informix. Oracle, Sybase. Solid. Postgre SQL, and Generic ODBC. The popular PHP-MySQL combination (both are open-source products) is available on almost every UNJX bost. Being web oriented. PHP also contains all the functions to do things on the internet-connecting to remove servers, check the email via POP3 or IMAP url encoding setting cookies, redirecting, etc. PHP tags: To open a block of PHP code in a page you can use one of these four sets of opening and closing tags Opening tags <? ?> <?php ?> <% %> <script language php> < /script> Closing tags

The first pair (<? ?>) is called short tag you avoid using short tags in your application especially if its meant to be distribute on other service. This is because short tags are not always supported (though I never seen any web bost that does not support it). Short tags are only available only especially enabled setting the short-open-tag value to on the PHP organization file php inl.

PHP - What's it do? It is also helpful to think of PHP in terms of what it can do for you. PHP will allow you to: Reduce the time to create large websites. Create a customized user experience for visitors based on information that you have gathered from them.

Open up thousands of possibilities for online tools. Check out PHP - HotScripts for examples of the great things that are possible with PHP. Allow creation of shopping carts for e-commerce websites. What You Should Know: Before starting this tutorial it is important that you have a basic understanding and experience in the following: HTML - Know the syntax and especially HTML Forms. Basic programming knowledge - This isn't required, but if you have any traditional programming experience it will make learning PHP a great deal easier.

Example Simple HTML & PHP Page: Below is an example of one of the easiest PHP and HTML page that you can create and still follow web standards. PHP and HTML Code: <html> <head> <title>My First PHP Page</title> </head> <body> <?php echo "Hello World!"; ?> </body> </html>

Display: Hello World! If you save this file and place it on PHP enabled server and load it up in your web browser, then you should see "Hello World!" displayed. If not, please check that you followed our example correctly. We used the PHP function echo to write "Hello World!" and we will be talking in greater depth about this PHP function and many others later on in this tutorial.

PHP installation: Before you start programming with PHP, you first acquire install & configure PHP interpreter. PHP is available for a lot of platform and work in configuration with web servers. Along with PHP itself and a web server, you also need a web Hypertext. The latest version of PHP can be downloaded from after the download is completed dont forget to unpack the archive. Step 1: download the file: Download the latest PHPs ZIP package from As always vires scan the file and check its MDS, check with setting _____________________________________________________________________________ Step 2: extract the file: We will install the PHP file to C:/php, so create that folder and contact the contents of ZIP file into it. PHP can be install anywhere in your systems, but you will have to change the path referenced in the following steps.

Step 3: configure php.inl Copy C:\php\php.ini-recommended to C:\php\php.ini. There are several lines you will need to change in a text editor (use search to find the current setting). Define the extension directory: 1. extension_dir=C:\php\ext Enable extensions. This will depend on the libraries you want to use, but the following extensions should be suitable for the majority of application (remove the semi-colon comment): 1. 2. 3. 4. 5. 6. 7. extension=php_curl.dil extension=php_gd2.dil extension=php_mbstring.dil extension=php_mysql.dil extension=php_mysqli.dil extension=php_pdo.dil extension=php_pdo_mysql.dil

8. extension=php_xmlrpe.dil If you want to send emails using the PHP mail () function. Enter the details of an SMTP server (you ISPs server should be suitable): 1. 2. 3. 4. 5. 6. [mail function] :For Win32 only smpt_port=25 :For Win32 only.

Step 4: add C:\php to the path environment variable To ensure Windows can find PHP, you need to change the path environment variable. From the Control Panel, choose System, (then Advanced system settings in Vista), select the Advanced tab, and click the Environment Variables button. Scroll down the system variables list and click on Path followed by the Edit button. Enter :C:\php to the end of the variables value line (remember the semi-colon). Step 5: configure PHP as an Apache module. Ensure Apache is not running (use net stop Apache2.2 from the command line) and open its \conf\httpd.conf configuration file in an editor. The following lines should be changed. Line 239, add index.php as a default file name: 1. DirectoryIndex index.php index.html At the bottom of the file, add the following lines (change the PHP file location if necessary): 1. 2. 3. 4. PHP5 module Load Module php5_modulec./php/php5apache2_2dil AddType application/x=httpd=php.php. PHPIniDirC:/php

Save the configuration file and test it from the command line (Start>Run>cmd): 1. cd\Apache2\bin 2. httpd-t Step 6: test a PHP file Create a file name index.php in Apaches web page root (either htdoes or D:\WebPages) and this code: 1. <?php phpinfo():?>

Ensure Apache has started successfully, open a web browser and enter the address http://Iocalhist/. If all goes well, a PHP version page should appear showing all the configuration settings. PHP Implementation: We are providing a PHP module to simplify the task of writing a web application using It is named CaptchasDotNet.php. To use it, simply copy it to somewhere in your PHP path or simply into the directory with the PHP-script using it. Building up HTML FORMS using PHP: Input Fields Input fields are the simplest forms to grasp. As mentioned in the Forms Tutorial, just be sure to place the name attribute within the tags and specify a name for the field. Also be aware that for our form's action we have placed the $PHP_SELF super global to send our form to itself. We will be integrating more PHP code into our form as we continue on so be sure to save the file with a .php extension. CODE:

<html> <head> <title>Personal INFO</title> </head> <body> <form method="post" action="<?php echo $PHP_SELF;?>"> First Name:<input type="text" size="12" maxlength="12" name="Fname">:<br /> Last Name:<input type="text" size="12" maxlength="36" name="Lname">:<br />

Radios and CheckboxesThe catch with radio buttons lies with the value attribute. The text you place under the value attribute will be displayed by the browser when the variable is called with PHP. Check boxes require the use of an array. PHP will automatically place the checked boxes into an array if you place [] brackets at the end of each name.


... Gender::<br /> Male:<input type="radio" value="Male" name="gender">:<br /> Female:<input type="radio" value="Female" name="gender">:<br /> Please choose type of residence::<br /> Steak:<input type="checkbox" value="Steak" name="food[]">:<br /> Pizza:<input type="checkbox" value="Pizza" name="food[]">:<br /> Chicken:<input type="checkbox" value="Chicken" name="food[]">:<br />

TextareasIn reality, textareas are oversized input fields. Treat them the same way, just be aware of the wrap attribute and how each type of wrap will turn out. PHP relys on this attribute to display the textarea. CODE:

... <textarea rows="5" cols="20" name="quote" wrap="physical"> Enter your favorite quote!</textarea>:<br />

Drop Down Lists & Selection ListsThese two forms act very similar to the already discussed radio and checkbox selections. To name a selection form, place the name attribute within the select tags at the beginning of the form, and then place the appropriate value to fit each option.


... Select a Level of Education:<br /> <select name="education">

<option value="Jr.High">Jr.High</option> <option value="HighSchool">HighSchool</option> <option value="College">College</option></select>:<br /> Select your favorite time of day::<br /> <select name="TofD" size="3"> <option value="Morning">Morning</option> <option value="Day">Day</option> <option value="Night">Night</option></select>:<br />
Be sure to check through your code to double check for bugs or errors especially look at each name attribute to be sure your names are all correct. As far as names go, you can copy the ones shown or simply make up your own, just be sure you remember what they are. Your form should be similar to the one shown here.

WEBSITES: PHP: Hypertext Processor Possible questions related to oral examinations: 1. What is PHP? 2. What are PHP tags?