1 / 18

COP 3813 Intro to Internet Computing

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

kalin
Télécharger la présentation

COP 3813 Intro to Internet Computing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COP 3813Intro to Internet Computing Prof. Roy Levow PHP

  2. 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

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

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

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

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

  7. 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

  8. Language Resources • Online PHP Manual http://www.php.net/manual/en/ • Tutorials • http://www.php.net/links.php#tutorials • http://www.w3schools.com • Google for many others

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

  10. Named Constants • define(“ONE”, 1); • do not have $ • must be scalars

  11. 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

  12. 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

  13. Operators • Comparable to C operators • Usual operators • arithmetic • comparison • logical • increment and decrement • op=

  14. 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

  15. 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}

  16. Environment • Server and Client Side • $_SERVER • $_ENV • $_GET • $_POST • $_COOKIE • $GLOBALS

  17. Form Processing • Examples: • fig 26.13 form.html • fig 26.14 form.php • Login • Example: • fig 26.15 password.html • fig 26.16 password.php

  18. PHP Examples • Cookies • fig 26.20 cookies.html • fig 26.21 readCookie.php • PHP and Database connectivity

More Related