Download
slide1 n.
Skip this Video
Loading SlideShow in 5 Seconds..
PHP PowerPoint Presentation

PHP

148 Views Download Presentation
Download Presentation

PHP

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. PHP 10 February 2011

  2. Review: Viewing a Web Page SERVER web page repository WEB PAGE instructions stores information and instructions BROWSER retrieves web page and follows instructions 2 1 3 Server Client Web Server Pages Browser

  3. Dynamic Web Pages • Two places you can change • Browser: JavaScript • Server: php • General rule: • do it in the browser if you can • Consider the difference in the date function… 2 1 3 Server Client Web Server Pages Browser

  4. Usage • PHP • > 25 million websites use PHP • 1/3 of the top million • JavaScript • Used by majority of websites • Almost no browsers preclude its use

  5. PHP Processing • Retrieve the web page • Reads each line • If NOT php, sends it on • If php, • Performs the action • Sends it on 2 3 Server Web Server Pages

  6. When I look at the HTML • If I look in komodo edit… • If I look through view page source… 2 1 3 Server Client Web Server Pages Browser

  7. Using PHP • Files must be .php rather than .html • Servers will use index.php if no index.html • PHP command format • <?php …; ?> • Commands always end with ; • Comments • Single line: // comment • Multiple line /* line continues */ • Need to UPLOAD before viewing

  8. Simple HTML Page with PHP The following is a basic example to output text using PHP Running on the server (isis), you would see “Hello World!” displayed.

  9. Conditional statement Display content according to the day of the week if statement checks numerical day of the week (0=Sunday… 6=Saturday) If equal to 5 (Fri) , display everything within the first { } bracket If not equal to 5, display everything in the second { } bracket If we run the script on a Friday, we should see:“See you Monday!”On other days, we will see:“See you tomorrow!”

  10. Header Page 1 Content Page 2 Content Page 3 Content Page 4 Content Page 5 Content Footer Implementing Templates - Any changes to header or footer only require editing of a single file. This reduces the amount of work necessary for site maintenance and redesign. - Helps separate the content and design for easier maintenance

  11. Server Side Includes Basic template to use on all of the pages. Make sure you name the files with a .php extension Assume the header and footer files are located in the same directory. Note that comments are PHP comments.

  12. header.php • Any html can be used • Best practice • Use balanced HTML tags • Start and end with comments for visibility

  13. Footer.php

  14. Using other php commands • You MAY, you NEED NOT • If you are interested, • Decide what function it brings • Commands to start with • echo to create HTML tags or text • date