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 Standard extension is .php
Basic Format <html>  … <body>  <?php echo &quot;Hello World&quot;; ?>  </body>  </html>
PHP File Form Script is embedded in HTML Bounded by  <?php  and  ?> 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 www.php.net
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
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 http://www.php.net/manual/en/ Tutorials http ://www.php.net/links.php#tutorials http://www.w3schools.com 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 26.13 form.html fig 26.14 form.php Login Example:  fig 26.15 password.html fig 26.16 password.php
PHP Examples Cookies fig 26.20 cookies.html fig 26.21 readCookie.php PHP and Database connectivity

Download It

  • 1.
    COP 3813 Introto Internet Computing Prof. Roy Levow PHP
  • 2.
    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 Standard extension is .php
  • 3.
    Basic Format <html> … <body> <?php echo &quot;Hello World&quot;; ?> </body> </html>
  • 4.
    PHP File FormScript is embedded in HTML Bounded by <?php and ?> Output replaces script code in page sent to client
  • 5.
    PHP Service Mustbe 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 ServicesA number of sites offer limited free PHP services The following site lists several http://www.0php.com/free_PHP_hosting.php
  • 7.
    Your PHP WorkYou 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 OnlinePHP 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 beginwith $ 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, integerfload, 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 rulesfor 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 toC 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 Patternmatching 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 andClient 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 Cookiesfig 26.20 cookies.html fig 26.21 readCookie.php PHP and Database connectivity