Sunteți pe pagina 1din 3

ITWP103 Lab Activity No. 2 Creating Basic PHP Script Objectives: 1.

Learn how to define and print constants and variables. 2. Applying modular web page design by identifying different HTML sections and converting it into separate include files. 3. Insert PHP code block in an HTML file to generate dynamic output. 4. Appreciate the purpose of comments in a code. 1. Design a web page design template or search a ready-made web template that has the sections listed below. Save the index.html file as c:\xampp\htdocs\yourfoldername\lab2.php. Save also all the necessary files under the same folder (image files, *.css, *.js, etc). If you already uploaded your web page template, download the files to your c:\xampp\htdocs\yourfoldername local computer. Test your http://localhost/yourfoldername/lab2.php and check if the page is working before proceeding to the next step. a. b. c. d. Header Section Footer Section Navigation Section Content Section Student details Copyright information List of laboratory activities (lab1.php to lab15.php) This will contain the output of your php code

Sample Template Page Structure

2. Under the same location of your lab2.php, create another file config.php and declare the following constants. Set the appropriate values. <?php define('NAME', 'your name...'); define('SN', 'your student number'); define('COURSE', 'your course'); ?> 3. In your lab2.php file, locate the header section and copy it to another file header.php. Replace the header section part with <?php include_once('header.php'); ?>. Test your lab2.php before proceeding to the next step. 4. In your header.php file, find the <title></title> element and print the title of your page using the constant PAGETITLE. Test your lab2.php and check if the title of the page is reflected before proceeding to the next step. You will declare the constant PAGETITLE later. Ex. <title><?php echo PAGETITLE; ?></title>

5. In your lab2.php file, locate the navigation section and copy it to another file navigation.php. Replace the navigation section part with <?php include_once('navigation.php'); ?>. Test your lab2.php before proceeding to the next step. 6. Modify your navigation.php and update the links for lab1.php and lab2.php. Test your lab2.php and check if the links are updated before proceeding to the next step. <a href="lab1.php">Hello World</a> <a href="lab2.php">Creating Basic PHP Script</a> 7. In your lab2.php file, locate the footer section and copy it to another file footer.php. Replace the footer section part with <?php include_once('footer.php'); ?>. Test your lab2.php before proceeding to the next step. 8. In your header.php file, print your NAME, STUDENTNO, and COURSE constants. <?php echo NAME, SN, COURSE; ?> 9. In your footer.php file, print a copyright information and rundate. Example: <?php echo '&copy; ', date('Y'), ' ', NAME, ' :: Rundate ', date('m/d/Y'); ?>

10. At the beginning of your lab2.php file, declare a constant PAGETITLE and set the value to 'Lab 2 Creating Basic PHP Script'. Include your config.php after that. Test your lab2.php and before proceeding to the next step. <?php define('PAGETITLE', 'Lab 2 Creating Basic PHP Script'); include_once('config.php'); ?> ... 11. In your lab2.php file, locate the content section part and replace it by an empty PHP code. ... <?php // TODO: output goes here ?> ... 12. Inside the PHP code in step 11, declare the following variables and assign the values accordingly: $school = 'University of the East'; $course $yearlevel $dateofbirth $sex 13. After the variable declarations print the variables inside a table. You may use table to layout the output. Example: echo echo echo echo echo echo echo echo '<table>'; '<tr><td colspan=2><strong>My Academic Information</strong></td></tr>'; '<tr><td>School</td><td>', $school, '</td></tr>'; '<tr><td>Course</td><td>', $course, '</td></tr>'; '<tr><td>Year Level</td><td>', $yearlevel, '</td></tr>'; '<tr><td>Date of Birth</td><td>', $dateofbirth, '</td></tr>'; '<tr><td>Sex</td><td>', $sex, '</td></tr>'; '</table>'

14. Your lab2.php must be similar to the following code. The placement of your include_once('navigation.php') depends on the layout of your template. It can be after the content or before the content section. <?php define('PAGETITLE', 'Lab 1 - Hello World'); include_once('config.php'); include_once('header.php'); ?> <div id="Content"> <?php // TODO: output goes here... ?> </div> <?php include_once('navigation.php'); // position varies include_once('footer.php'); ?> 15. Test your final lab2.php. The following files must be uploaded in a free webhosting site using the File Manager. a. b. c. d. e. f. lab2.php config.php - reusable for lab2 header.php - reusable for lab2 navigation.php - reusable for lab2 footer.php - reusable for lab2 Template files (image, css, js, etc) lab15 lab15 lab15 lab15

16. Good luck and happy coding!

S-ar putea să vă placă și