220 likes | 474 Vues
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.
E N D
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 • 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
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
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
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
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
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.
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!”
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
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.
header.php • Any html can be used • Best practice • Use balanced HTML tags • Start and end with comments for visibility
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