Lab #3 - PHP Basics (Functions & Multiple Files)
Purpose: Multiple page site using multiple PHP pages
Instructions
- Create a PHP file, called "index.php", that performs the following actions:
- [index.php] include the file "header.php"
- [index.php] switch on the variable $_GET['pg']
- [index.php] create a default case that displays
<h2>404 Error</h2><p>The requested page was not available</p>
- [index.php] include the file "footer.php"
- Create a PHP file, called "header.php", that performs the following actions:
- [header.php] Prints the following HTML, with the class "currentPage" assigned to the correct navigation item based on the value of $_GET['pg']
<!DOCTYPE html> <html> <head> <title>[title goes here]</title> <link rel="stylesheet" href="/style.css" type="text/css" media="all"> </head> <body> <header> <h1>Programming Languages</h1> <nav> <a href="?pg=c" class="">C</a> <a href="?pg=cpp" class="">C++</a> <a href="?pg=java" class="">Java</a> <a href="?pg=fortran" class="">Fortran</a> <a href="?pg=prolog" class="">ProLog</a> </nav> </header> <main>
- Create a PHP file, called "footer.php", the prints the following code. Substitute the result of the date function call provided in the appropriate place in the HTML
</main> <script type="text/javascript" src="/theme/prism.js"></script> <footer>©2023-01-09 15:01 - General Websites Inc.</footer> </body> </html>
date_default_timezone_set('America/Chicago'); $date_string = date('Y-m-d H:i');
- Create a PHP file called "pages.php".
- [pages.php] Create a function for each page in the website. Each function should print out the content contained within the <main> tags in the example site. You may copy and paste from the example sites HTML to reduce the amount of typing of the HTML you need to do.
- [index.php] Add the following line to the file, prior to the switch statement
require('pages.php');
- [index.php] Modify your switch statement to create a case for each page. In each of those cases, you should call the function you defined in the pages.php file
- [index.php] Before any of the includes or switch statement, add the following line of code
if (!isset($_GET['pg'])) { $_GET['pg'] = 'c'; }
- Upload your PHP files (if you have not been doing that to test your code as you go), to the remote server. Please the file in "public_html/csci2006/lab03/index.php"
- In a web-browser, go to the URL below
- Ensure that your code is not producing any errors or warnings, by using the log-access tool. If you have trouble understanding the log messages, please email me for assistance. Note the log does not reset, so you need to look at when any errors/warnings occurred and which HTTP request they were for to better understand whether you have already fixed that issue
Submitting Instructions
- Upload a screenshot of your site, on a page of your choosing