84
PHP started out as a small open source project that evolved as more and more people found out how useful it was. Rasmus Lerdorf unleashed the first version of PHP way back in 1994. PHP is a recursive acronym for "PHP: Hypertext Preprocessor". PHP is a server side scripting language that is embedded in HTML. It is used to manage dynamic content, databases, session tracking, even build entire e-commerce sites. It is integrated with a number of popular databases, including MySQL, PostgreSQL, Oracle, Sybase, Informix, and Microsoft SQL Server. PHP is pleasingly zippy in its execution, especially when compiled as an Apache module on the Unix side. The MySQL server, once started, executes even very complex queries with huge result sets in record-setting time. PHP supports a large number of major protocols such as POP3, IMAP, and LDAP. PHP4 added support for Java and distributed object architectures (COM and CORBA), making n-tier development a possibility for the first time. PHP is forgiving: PHP language tries to be as forgiving as possible. PHP Syntax is C-Like. Common uses of PHP: PHP performs system functions, i.e. from files on a system it can create, open, read, write, and close them. PHP can handle forms, i.e. gather data from files, save data to a file, thru email you can send data, return data to the user. You add, delete, modify elements within your database thru PHP. Access cookies variables and set cookies. Using PHP, you can restrict users to access some pages of your website. It can encrypt data. Characteristics of PHP Five important characteristics make PHP's practical nature possible: Simplicity Efficiency Security Flexibility Familiarity

Php

Embed Size (px)

DESCRIPTION

p

Citation preview

PHP started out as a small open source project that evolved as more and more people found out how usefulit was. Rasmus Lerdorf unleashed the first version of PHP way back in 1994. PHP is a recursive acronym for PHP! Hyperte"t Preprocessor. PHP is a server side scriptin# lan#ua#e that is embedded in H$%L. &t is used to mana#e dynamiccontent' databases' session trackin#' even build entire e(commerce sites. &t is inte#rated with a number of popular databases' includin# %y)*L' Post#re)*L' +racle' )ybase'&nformi"' and %icrosoft )*L )erver. PHP is pleasin#ly ,ippy in its e"ecution' especially when compiled as an -pache module on the .ni"side. $he %y)*L server' once started' e"ecutes even very comple" /ueries with hu#e result sets inrecord(settin# time. PHP supports a lar#e number of major protocols such as P+P0' &%-P' and L1-P. PHP4 added supportfor 2avaanddistributedobject architectures34+%and4+R5-6' makin#n(tier development apossibility for the first time. PHP is for#ivin#! PHP lan#ua#e tries to be as for#ivin# as possible. PHP )ynta" is 4(Like.Common uses of PHP: PHP performs system functions' i.e. from files on a system it can create' open' read' write' andclose them. PHP can handle forms' i.e. #ather data from files' save data to a file' thru email you can send data'return data to the user. 7ou add' delete' modify elements within your database thru PHP. -ccess cookies variables and set cookies. .sin# PHP' you can restrict users to access some pa#es of your website. &t can encrypt data.Characteristics of PHP8ive important characteristics make PHP9s practical nature possible! )implicity :fficiency )ecurity 8le"ibility 8amiliarity"Hello World" Script in PHP:$o #et a feel for PHP' first start with simple PHP scripts. )ince Hello' ;orld< is an essential e"ample' firstwe will create a friendly little Hello' ;orld< script.-s mentioned earlier' PHP is embedded in H$%L. $hat means that in amon#st your normal H$%L 3or =H$%Lif you9re cuttin#(ed#e6 you9ll have PHP statements like this!

Hello World

&t will produce followin# result!Hello, World!&f you e"amine the H$%L output of the above e"ample' you9ll notice that the PHP code is not present in thefile sent from the server to your ;eb browser. -ll of the PHP present in the ;eb pa#e is processed andstripped from the pa#e> the only thin# returned to the client from the ;eb server is pure H$%L output.-ll PHP code must be included inside one of the three special markup ta#s ate are reco#nised by the PHPParser.

PHP code goes here %ost common ta# is the ?@php...@A and we will also use same ta# in our tutorial.8rom the ne"t chapter we will start with PHP :nvironment )etup on your machine and then we will di# outalmost all concepts related to PHP to make you comfortable with the PHP lan#ua#e.&n order to develop and run PHP ;eb pa#es three vital components need to be installed on your computersystem. Web Server - PHP will work with virtually all ;eb )erver software' includin# %icrosoft9s &nternet&nformation)erver 3&&)6 but thenmost oftenusedisfreelyavailble-pache)erver.1ownload-pache for free here! http!BBhttpd.apache.or#Bdownload.c#i Database -PHPwill work with virtuallyalldatabasesoftware'includin#+racle and )ybase butmost commonly used is freely available %y)*L database. 1ownload %y)*L for free here!http!BBwww.mys/l.comBdownloadsBinde".html PHP Parser -&n order to process PHP script instructions a parser must be installed to #enerateH$%L output that can be sent to the ;eb 5rowser. $his tutorial will #uide you how to install PHPparser on your computer.PHP Parser Installation:5efore you proceed it is important to make sure that you have proper environment setup on your machineto develop your web pro#rams usin# PHP.$ype the followin# address into your browser9s address bo".http//!"#$%$%$!/in&o$php&f this displays a pa#e showin# your PHP installation related information then it means you have PHP and;ebserver installed properly. +therwise you have to follow #iven procedure to install PHP on your computer.$his section will #uide you to install and confi#ure PHP over the followin# four platforms! PHP &nstallation on Linu" or .ni" with -pache PHP &nstallation on %ac +) = with -pache PHP &nstallation on ;indows C$BDEEEB=P with &&) PHP &nstallation on ;indows C$BDEEEB=P with -pacheApache Confguration:&f you are usin# -pache as a ;eb )erver then this section will #uide you to edit -pache 4onfi#uration 8iles.2ust 4heck it here ! PHP 4onfi#uration in -pache )erverPHP.INI File Confguration:$he PHP confi#uration file' php.ini' is the final and most immediate way to affect PHP9s functionality.2ust 4heck it here! PHP.&C& 8ile 4onfi#urationWindows IIS Confguration:$o confi#ure &&) on your ;indows machine you can refer your &&) Reference %anual shipped alon# with &&).$hischapterwill #iveyouanideaof verybasicsynta"of PHPandveryimportant tomakeyour PHPfoundation stron#.Escaping to PHP:$hePHPparsin#en#ineneedsawaytodifferentiatePHPcodefromotherelementsinthepa#e. $hemechanism for doin# so is known as 9escapin# to PHP.9 $here are four ways to do this!Canonical PHP tags:$he most universally effective PHP ta# style is!

&f you use this style' you can be positive that your ta#s will always be correctly interpreted.Short-open (SGML-style) tags:)hort or short(open ta#s look like this!

)hort ta#s are' as one mi#ht e"pect' the shortest option 7ou must do one of two thin#s to enable PHP toreco#ni,e the ta#s! 4hoose the ((enable(short(ta#s confi#uration option when you9re buildin# PHP. )et the shortFopenFta# settin# in your php.ini file to on. $his option must be disabled to parse =%Lwith PHP because the same synta" is used for =%L ta#s.ASP-style tags:-)P(style ta#s mimic the ta#s used by -ctive )erver Pa#es to delineate code blocks. -)P(style ta#s look likethis!

$o use -)P(style ta#s' you will need to set the confi#uration option in your php.ini file.HML script tags:H$%L script ta#s look like this!$$$Commenting PHP Code:-commentistheportionof apro#ramthate"istsonlyforthehumanreaderandstrippedoutbeforedisplayin# the pro#rams result. $here are two commentin# formats in PHP!Single-line co!!ents: $hey are #enerally used for short e"planations or notes relevant to the local code.Here are the e"amples of sin#le line comments.

M"lti-linesco!!ents:$heyare#enerallyusedtoprovidepseudocodeal#orithmsandmoredetailede"planations when necessary. $he multiline style of commentin# is the same as in 4. Here are the e"ampleof multi lines comments.

&t will produce followin# result!

WhatBs .or 0innerhttp//menu$e,ample$com/7hoose -hat to eat tonight$