INQ177CJ
Computational Aspects of E‑commerce

Activity 8

PHP Introduction

Time Greeting

Create a new php web page that displays a time dependent greeting to the user by doing the following:

  1. Add html code to the file like you are creating an html page.

  2. Add php tags to the body.

  3. Create a variable called $hour and set it equal to a number between 0 and 23.

  4. Write an if/elseif/else statement that echoes:

    1. “Good Morning” if $hour is between 6 and 11 (inclusive)
    2. “Good Afternoon” if $hour is between 12 and 17 (inclusive)
    3. “Good Evening” if $hour is between 18 and 23 (inclusive) or if $hour is between 0 and 5 (inclusive)

    Note, you can do this with what you learned in the tutorial but it is a little easier with logical operators, which weren’t in the tutorial. Read the PHP logical operators documentation for help.

  5. Test the code by changing the value of the $hour variable and reloading the page.

  6. To make the page use the actual time, replace the variable defintion line with the code:

    $hour = intval(date('G', time()));

Submission

Please show your completed web page and source code to the instructor.