1 / 14

PHP

PHP. 10 February 2011. 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. Dynamic Web Pages.

kelvin
Télécharger la présentation

PHP

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

More Related