COP 3813 Intro to Internet Computing Prof. Roy Levow PHP
PHP PHP: Hypertext Processor 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 –Standard extension is.php
Basic Format …
PHP File Form Script is embedded in HTML Bounded by and Bounded by Output replaces script code in page sent to client
PHP Service Must be installed on server Enabled in web server Versions for –Apache and IIS –No many platforms Primary site for PHP
Free PHP Services A number of sites offer limited free PHP services The following site lists several ting.php ting.php ting.php
Your PHP Work You need a place to work with PHP You may do any of the following provided that the hosting site is publicly accessible –Set up PHP on your own server –Subscribe to a free hosting site –Use any other hosting site
Language Resources Online PHP Manual Tutorials – – –Google for many others
Variables Names begin with $ followed by string of letters and digits Case sensitive No declarations Type determined by value $num = 5; $myName = “Prof. Levow”
Named Constants define(“ONE”, 1); –do not have $ –must be scalars
Types int, integer fload, double string //enclosed in ‘ or “ bool, Boolean //true or false array //actually a map object // for O-O programming NULL //no value
Constants Typical rules for numbers and strings Usual \ escapes in strings settype($var, “type”) –function to change type of a value –actually changes type of stored value (type) expr –typical “C” cast of value Example: Fig. 26.3, data.php
Operators Comparable to C operators Usual operators –arithmetic –comparison –logical –increment and decrement op=
String Operators . for concatenation variable interpolation with “ “ –embedded variable reference is replaced by value –example: “My name is $name.” numeric valued strings converted for arithmetic –7 + “3” yields 10
Regular Expressions Pattern matching in strings –ereg, eregi (reg_exp, $search, $match) –Meta characters: * + ? ^ $. –Character class [list] a-z :alpha:, :alnum:, :digit:, :space:, :lower:, :upper: –Repetition: {n}, {m,n}, {,n}
Environment Server and Client Side –$_SERVER –$_ENV –$_GET –$_POST –$_COOKIE –$GLOBALS
Form Processing Examples: –fig form.html –fig form.php Login –Example: fig password.html fig password.php
PHP Examples Cookies –fig cookies.html –fig readCookie.php PHP and Database connectivity