1 / 25

CPSP 229D: Web desiGN

ALBERT WAVERING BOBBY SENG. CPSP 229D: Web desiGN. Week Whatever: PHP. Announcements/questions/complaints. What is PHP?. Server-side scripting language P HP: H ypertext P rocessor Created in 1995; current version 5.3.3 Dynamically typed (like JavaScript) Other scripting languages:

willoughby
Download Presentation

CPSP 229D: Web desiGN

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. ALBERT WAVERING BOBBY SENG CPSP 229D: Web desiGN

  2. Week Whatever: PHP • Announcements/questions/complaints

  3. What is PHP? • Server-side scripting language • PHP: Hypertext Processor • Created in 1995; current version 5.3.3 • Dynamically typed (like JavaScript) • Other scripting languages: • Microsoft ASP • Adobe ColdFusion • Java (using JSP) • Ruby (using Rails)

  4. PHP • Scripts are stored on a server • Interpreted on servers when a page is requested • I request example.php • Server looks up the file • PHP software processes PHP file • Output is HTML+CSS+JavaScript that is returned as the requested page

  5. Real Life Examples • Facebook • ‘Compressed’ PHP • Wikipedia • Photobucket • Yahoo! • YouTube

  6. PHP • Can run on most operating systems • Compatible with most servers (Apache, IIS, etc) • Lets you create dynamic webpages • Most useful when you want to insert specific custom data • Where does this data come from? • Databases!

  7. PHP + MySQL • MySQL is a Structured Query Language database platform • PHP has native built-in support for MySQL • While interpreting a PHP script, PHP software can make multiple requests to multiple MySQL databases • PHP also supports many other databases

  8. PHP Basics • PHP Script can contain: • HTML • CSS • JavaScript • PHP script • PHP files have extension .php • If you save them as .html, the PHP software will not process them • Closed source – your users cannot read your code (unlike JavaScript)

  9. PHP Basics • PHP scripts are written inside a <?php ?> tag • Anything you want interpreted has to be inside these tags • Example: <html><body><?phpecho "Hello World";?></body></html>

  10. PHP Basics • Like Java, every line in PHP ends with a semicolon; • //Single-line comments • /*Multi-linecomments*/

  11. PHP Basics • PHP variable names are always preceded by a $ • Assigning a value to a variable:$variable_name = value; • PHP variables are loosely typed • Don’t have to declare variables before using them • Can reassign variables to hold different types of values

  12. PHP Basics • Variables can only include alphanumeric characters and the underscore • Variables must start with a letter or an underscore • PHP variables have a single scope, usually • Variables in functions are limited to those functions • The keyword global will use global variables inside a function

  13. The global keyword <?php$a = 1;$b = 2;function Sum(){    global $a, $b;    $b = $a + $b;} Sum();echo $b;?>

  14. Operators + Addition += - Subtraction -= * Multiplication *= / Division /= % Modulus %= ++ Increment -- Decrement = Assignment .= Concatenate (Strings)

  15. Comparison Operators == Equal to != Not equal to <> < Less than <= Less than or equal to > Greater than >= Greater than or equal to

  16. Logical Operators && and AND || or OR ! not xor XOR

  17. If/elseif/else if (condition) statement; elseif (condition) statement; else statement;

  18. Switch switch(variable){ case a: statement; break; case b: statement; break; default: statement; }

  19. Loops while (condition){ statements; } for (initialization; condition; increment){ statements; }

  20. Arrays • Numerically indexed • Associatively indexed (maps) • Multidimensional (combination of one or any of the above) • Create an array with $var_name = array(); • Index with $var_name[0] = assignment; or $var_name[$other_var] = assignment;

  21. PHP GET • Built-in functions to get data from pages • $_GET function collects values from a form sent with method = get HTML Page: <form action="welcome.php" method="get"> Name: <input type="text" name="fname" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> PHP Response: Welcome <?php echo $_GET["fname"]; ?>.<br /> You are <?php echo $_GET["age"]; ?> years old!

  22. PHP POST • Get is limited to 100 characters • Not awesome • Post has 8Mb maximum • Awesome

  23. PHP Post HTML Page: <form action="welcome.php" method="post"> Name: <input type="text" name="fname" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> PHP Response: Welcome <?php echo $_POST["fname"]; ?>.<br /> You are <?php echo $_POST["age"]; ?> years old!

  24. Resources • Ask Jeeves • AltaVista • http://php.net/manual/en • Language Reference • Your new best friend • Code examples, user questions, hints • http://www.w3schools.com/php/default.asp

  25. Homework • Create a PHP script that outputs the current date to a page, inserted among other usual HTML elements in a full page • http://php.net/manual/en/function.date.php • Use one additional construct of PHP (array, loop, if/else, etc) • Upload to your account on my server as a .php file by the start of next class • Be creative! • Databases next time (real fun starts)

More Related