Upload
clark
View
30
Download
2
Embed Size (px)
DESCRIPTION
COP 3813 Intro to Internet Computing. Prof. Roy Levow PHP. PHP. P HP: H ypertext P rocessor Server-side scripting Script embedded in html Script runs on server Allows secure access to resources on server – database, file, etc. Hides program code from users But, more network traffic - PowerPoint PPT Presentation
Citation preview
COP 3813COP 3813Intro to Internet Intro to Internet
ComputingComputing
Prof. Roy LevowProf. Roy Levow
PHPPHP
PHPPHP
PPHP: HP: HHypertext ypertext PProcessorrocessor Server-side scriptingServer-side scripting
– Script embedded in htmlScript embedded in html– Script runs on serverScript runs on server– Allows secure access to resources on Allows secure access to resources on
server – database, file, etc.server – database, file, etc.– Hides program code from usersHides program code from users– But, more network trafficBut, more network traffic– Standard extension is .phpStandard extension is .php
Basic FormatBasic Format
<html> …<body>
<?php echo "Hello World"; ?>
</body> </html>
PHP File FormPHP File Form
Script is embedded in HTMLScript is embedded in HTML Bounded by Bounded by <?php and and ?> Output replaces script code in page Output replaces script code in page
sent to clientsent to client
PHP ServicePHP Service
Must be installed on serverMust be installed on server Enabled in web serverEnabled in web server Versions forVersions for
– Apache and IISApache and IIS– No many platformsNo many platforms
Primary site for PHPPrimary site for PHPwww.php.netwww.php.net
Free PHP ServicesFree PHP Services
A number of sites offer limited free A number of sites offer limited free PHP servicesPHP services
The following site lists several The following site lists several http://www.0php.com/free_PHP_hostihttp://www.0php.com/free_PHP_hosting.phpng.php
Your PHP WorkYour PHP Work
You need a place to work with PHPYou need a place to work with PHP You may do any of the following You may do any of the following
provided that the hosting site is provided that the hosting site is publicly accessiblepublicly accessible– Set up PHP on your own serverSet up PHP on your own server– Subscribe to a free hosting site Subscribe to a free hosting site – Use any other hosting siteUse any other hosting site
Language ResourcesLanguage Resources
Online PHP ManualOnline PHP Manual
http://www.php.net/manual/en/http://www.php.net/manual/en/ TutorialsTutorials
– httphttp://www.php.net/links.php#tutorials://www.php.net/links.php#tutorials– http://www.w3schools.comhttp://www.w3schools.com– Google for many othersGoogle for many others
VariablesVariables
Names begin with $ followed by Names begin with $ followed by string of letters and digitsstring of letters and digits
Case sensitiveCase sensitive No declarationsNo declarations Type determined by valueType determined by value
$num = 5;$num = 5;$myName = “Prof. Levow”$myName = “Prof. Levow”
Named ConstantsNamed Constants
define(“ONE”, 1);define(“ONE”, 1);– do not have $do not have $– must be scalarsmust be scalars
TypesTypes
int, integerint, integer fload, doublefload, double string //enclosed in ‘ or “string //enclosed in ‘ or “ bool, Boolean //true or falsebool, Boolean //true or false array //actually a maparray //actually a map object // for O-O programmingobject // for O-O programming NULL //no valueNULL //no value
ConstantsConstants
Typical rules for numbers and stringsTypical rules for numbers and strings Usual \ escapes in stringsUsual \ escapes in strings settype($var, “type”) settype($var, “type”)
– function to change type of a valuefunction to change type of a value– actually changes type of stored valueactually changes type of stored value
(type) expr(type) expr– typical “C” cast of valuetypical “C” cast of value
Example: Fig. 26.3, data.phpExample: Fig. 26.3, data.php
OperatorsOperators
Comparable to C operatorsComparable to C operators Usual operatorsUsual operators
– arithmetic arithmetic – comparisoncomparison– logical logical – increment and decrementincrement and decrement
op=op=
String OperatorsString Operators
.. for concatenation for concatenation variable interpolation with “ “variable interpolation with “ “
– embedded variable reference is embedded variable reference is replaced by valuereplaced by value
– example: “My name is $name.”example: “My name is $name.” numeric valued strings converted for numeric valued strings converted for
arithmeticarithmetic– 7 + “3” yields 107 + “3” yields 10
Regular ExpressionsRegular Expressions
Pattern matching in stringsPattern matching in strings– ereg, eregiereg, eregi
(reg_exp, $search, $match)(reg_exp, $search, $match)
– Meta characters: * + ? ^ $ .Meta characters: * + ? ^ $ .– Character class [list]Character class [list]
a-za-z:alpha:, :alnum:, :digit:, :space:, :lower:, :upp:alpha:, :alnum:, :digit:, :space:, :lower:, :upp
er:er:
– Repetition: {n}, {m,n}, {,n}Repetition: {n}, {m,n}, {,n}
EnvironmentEnvironment
Server and Client SideServer and Client Side– $_SERVER$_SERVER– $_ENV$_ENV– $_GET$_GET– $_POST$_POST– $_COOKIE$_COOKIE– $GLOBALS$GLOBALS
Form ProcessingForm Processing
Examples: Examples: – fig 26.13 form.htmlfig 26.13 form.html– fig 26.14 form.phpfig 26.14 form.php
LoginLogin– Example: Example:
fig 26.15 password.htmlfig 26.15 password.htmlfig 26.16 password.phpfig 26.16 password.php
PHP ExamplesPHP Examples
CookiesCookies– fig 26.20 cookies.htmlfig 26.20 cookies.html– fig 26.21 readCookie.phpfig 26.21 readCookie.php
PHP and Database connectivityPHP and Database connectivity