CSCI 2006 - Spring 2024 - Server-Side ProgrammingLab #3 - PHP Basics (Functions & Multiple Files)

Lab #3 - PHP Basics (Functions & Multiple Files)

Purpose: Multiple page site using multiple PHP pages

Instructions

  1. Create a PHP file, called "index.php", that performs the following actions:
  2. [index.php] include the file "header.php"
  3. [index.php] switch on the variable $_GET['pg']
  4. [index.php] create a default case that displays
    <h2>404 Error</h2><p>The requested page was not available</p>
  5. [index.php] include the file "footer.php"
  6. Create a PHP file, called "header.php", that performs the following actions:
  7. [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>
  8. 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>&copy;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');
  9. Create a PHP file called "pages.php".
  10. [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.
  11. [index.php] Add the following line to the file, prior to the switch statement
    require('pages.php');
  12. [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
  13. [index.php] Before any of the includes or switch statement, add the following line of code
    if (!isset($_GET['pg'])) { $_GET['pg'] = 'c'; }
  14. 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"
  15. In a web-browser, go to the URL below
  16. 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