Download It

1,323 views
1,297 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,323
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Download It

  1. 1. COP 3813 Intro to Internet Computing Prof. Roy Levow PHP
  2. 2. PHP <ul><li>P HP: H ypertext P rocessor </li></ul><ul><li>Server-side scripting </li></ul><ul><ul><li>Script embedded in html </li></ul></ul><ul><ul><li>Script runs on server </li></ul></ul><ul><ul><li>Allows secure access to resources on server – database, file, etc. </li></ul></ul><ul><ul><li>Hides program code from users </li></ul></ul><ul><ul><li>But, more network traffic </li></ul></ul><ul><ul><li>Standard extension is .php </li></ul></ul>
  3. 3. Basic Format <ul><li><html> … <body> </li></ul><ul><li><?php echo &quot;Hello World&quot;; ?> </li></ul><ul><li></body> </html> </li></ul>
  4. 4. PHP File Form <ul><li>Script is embedded in HTML </li></ul><ul><li>Bounded by <?php and ?> </li></ul><ul><li>Output replaces script code in page sent to client </li></ul>
  5. 5. PHP Service <ul><li>Must be installed on server </li></ul><ul><li>Enabled in web server </li></ul><ul><li>Versions for </li></ul><ul><ul><li>Apache and IIS </li></ul></ul><ul><ul><li>No many platforms </li></ul></ul><ul><li>Primary site for PHP </li></ul><ul><ul><li>www.php.net </li></ul></ul>
  6. 6. Free PHP Services <ul><li>A number of sites offer limited free PHP services </li></ul><ul><li>The following site lists several http://www.0php.com/free_PHP_hosting.php </li></ul>
  7. 7. Your PHP Work <ul><li>You need a place to work with PHP </li></ul><ul><li>You may do any of the following provided that the hosting site is publicly accessible </li></ul><ul><ul><li>Set up PHP on your own server </li></ul></ul><ul><ul><li>Subscribe to a free hosting site </li></ul></ul><ul><ul><li>Use any other hosting site </li></ul></ul>
  8. 8. Language Resources <ul><li>Online PHP Manual </li></ul><ul><li>http://www.php.net/manual/en/ </li></ul><ul><li>Tutorials </li></ul><ul><ul><li>http ://www.php.net/links.php#tutorials </li></ul></ul><ul><ul><li>http://www.w3schools.com </li></ul></ul><ul><ul><li>Google for many others </li></ul></ul>
  9. 9. Variables <ul><li>Names begin with $ followed by string of letters and digits </li></ul><ul><li>Case sensitive </li></ul><ul><li>No declarations </li></ul><ul><li>Type determined by value </li></ul><ul><li>$num = 5; </li></ul><ul><li>$myName = “Prof. Levow” </li></ul>
  10. 10. Named Constants <ul><li>define(“ONE”, 1); </li></ul><ul><ul><li>do not have $ </li></ul></ul><ul><ul><li>must be scalars </li></ul></ul>
  11. 11. Types <ul><li>int, integer </li></ul><ul><li>fload, double </li></ul><ul><li>string //enclosed in ‘ or “ </li></ul><ul><li>bool, Boolean //true or false </li></ul><ul><li>array //actually a map </li></ul><ul><li>object // for O-O programming </li></ul><ul><li>NULL //no value </li></ul>
  12. 12. Constants <ul><li>Typical rules for numbers and strings </li></ul><ul><li>Usual escapes in strings </li></ul><ul><li>settype($var, “type”) </li></ul><ul><ul><li>function to change type of a value </li></ul></ul><ul><ul><li>actually changes type of stored value </li></ul></ul><ul><li>(type) expr </li></ul><ul><ul><li>typical “C” cast of value </li></ul></ul><ul><li>Example: Fig. 26.3, data.php </li></ul>
  13. 13. Operators <ul><li>Comparable to C operators </li></ul><ul><li>Usual operators </li></ul><ul><ul><li>arithmetic </li></ul></ul><ul><ul><li>comparison </li></ul></ul><ul><ul><li>logical </li></ul></ul><ul><ul><li>increment and decrement </li></ul></ul><ul><li>op= </li></ul>
  14. 14. String Operators <ul><li>. for concatenation </li></ul><ul><li>variable interpolation with “ “ </li></ul><ul><ul><li>embedded variable reference is replaced by value </li></ul></ul><ul><ul><li>example: “My name is $name.” </li></ul></ul><ul><li>numeric valued strings converted for arithmetic </li></ul><ul><ul><li>7 + “3” yields 10 </li></ul></ul>
  15. 15. Regular Expressions <ul><li>Pattern matching in strings </li></ul><ul><ul><li>ereg, eregi </li></ul></ul><ul><ul><ul><li>(reg_exp, $search, $match) </li></ul></ul></ul><ul><ul><li>Meta characters: * + ? ^ $ . </li></ul></ul><ul><ul><li>Character class [list] </li></ul></ul><ul><ul><ul><li>a-z </li></ul></ul></ul><ul><ul><ul><li>:alpha:, :alnum:, :digit:, :space:, :lower:, :upper: </li></ul></ul></ul><ul><ul><li>Repetition: {n}, {m,n}, {,n} </li></ul></ul>
  16. 16. Environment <ul><li>Server and Client Side </li></ul><ul><ul><li>$_SERVER </li></ul></ul><ul><ul><li>$_ENV </li></ul></ul><ul><ul><li>$_GET </li></ul></ul><ul><ul><li>$_POST </li></ul></ul><ul><ul><li>$_COOKIE </li></ul></ul><ul><ul><li>$GLOBALS </li></ul></ul>
  17. 17. Form Processing <ul><li>Examples: </li></ul><ul><ul><li>fig 26.13 form.html </li></ul></ul><ul><ul><li>fig 26.14 form.php </li></ul></ul><ul><li>Login </li></ul><ul><ul><li>Example: </li></ul></ul><ul><ul><ul><li>fig 26.15 password.html </li></ul></ul></ul><ul><ul><ul><li>fig 26.16 password.php </li></ul></ul></ul>
  18. 18. PHP Examples <ul><li>Cookies </li></ul><ul><ul><li>fig 26.20 cookies.html </li></ul></ul><ul><ul><li>fig 26.21 readCookie.php </li></ul></ul><ul><li>PHP and Database connectivity </li></ul>

×