COP 3813 Intro to Internet Computing Prof Roy

  • Slides: 18
Download presentation
COP 3813 Intro to Internet Computing Prof. Roy Levow PHP

COP 3813 Intro to Internet Computing Prof. Roy Levow PHP

PHP u PHP: Hypertext Processor u Server-side scripting – Script embedded in html –

PHP u PHP: Hypertext Processor u 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 <html> … <body> <? php echo "Hello World"; ? > </body> </html>

Basic Format <html> … <body> <? php echo "Hello World"; ? > </body> </html>

PHP File Form u Script is embedded in HTML u Bounded by <? php

PHP File Form u Script is embedded in HTML u Bounded by <? php and ? > u Output replaces script code in page sent to client

PHP Service u Must be installed on server u Enabled in web server u

PHP Service u Must be installed on server u Enabled in web server u Versions for – Apache and IIS – No many platforms u Primary site for PHP www. php. net

Free PHP Services u. A number of sites offer limited free PHP services u

Free PHP Services u. A number of sites offer limited free PHP services u The following site lists several http: //www. 0 php. com/free_PHP_hos ting. php

Your PHP Work u You need a place to work with PHP u You

Your PHP Work u You need a place to work with PHP u 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 u Online PHP Manual http: //www. php. net/manual/en/ u Tutorials – http:

Language Resources u Online PHP Manual http: //www. php. net/manual/en/ u Tutorials – http: //www. php. net/links. php#tutorials – http: //www. w 3 schools. com – Google for many others

Variables u Names begin with $ followed by string of letters and digits u

Variables u Names begin with $ followed by string of letters and digits u Case sensitive u No declarations u Type determined by value $num = 5; $my. Name = “Prof. Levow”

Named Constants u define(“ONE”, 1); – do not have $ – must be scalars

Named Constants u define(“ONE”, 1); – do not have $ – must be scalars

Types u int, integer u fload, double u string //enclosed in ‘ or “

Types u int, integer u fload, double u string //enclosed in ‘ or “ u bool, Boolean //true or false u array //actually a map u object // for O-O programming u NULL //no value

Constants u Typical rules for numbers and strings u Usual  escapes in strings

Constants u Typical rules for numbers and strings u Usual escapes in strings u settype($var, “type”) – function to change type of a value – actually changes type of stored value u (type) expr – typical “C” cast of value u Example: Fig. 26. 3, data. php

Operators u Comparable to C operators u Usual operators – arithmetic – comparison –

Operators u Comparable to C operators u Usual operators – arithmetic – comparison – logical – increment and decrement u op=

String Operators u. for concatenation u variable interpolation with “ “ – embedded variable

String Operators u. for concatenation u variable interpolation with “ “ – embedded variable reference is replaced by value – example: “My name is $name. ” u numeric valued strings converted for arithmetic – 7 + “ 3” yields 10

Regular Expressions u Pattern matching in strings – ereg, eregi u (reg_exp, $search, $match)

Regular Expressions u Pattern matching in strings – ereg, eregi u (reg_exp, $search, $match) – Meta characters: * + ? ^ $. – Character class [list] u a-z u : alpha: , : upper: : alnum: , : digit: , : space: , : lower: , – Repetition: {n}, {m, n}, {, n}

Environment u Server and Client Side – $_SERVER – $_ENV – $_GET – $_POST

Environment u Server and Client Side – $_SERVER – $_ENV – $_GET – $_POST – $_COOKIE – $GLOBALS

Form Processing u Examples: – fig 26. 13 form. html – fig 26. 14

Form Processing u Examples: – fig 26. 13 form. html – fig 26. 14 form. php u Login – Example: u fig 26. 15 password. html u fig 26. 16 password. php

PHP Examples u Cookies – fig 26. 20 cookies. html – fig 26. 21

PHP Examples u Cookies – fig 26. 20 cookies. html – fig 26. 21 read. Cookie. php u PHP and Database connectivity