Hull Design Online

Time Greeting

Good Afternoon from UTC

Page 1 | Page 2 | Page 3 | Page 4

Have you ever wondered how websites show a greeting according to the time? Let's find out how to do just that, using PHP. Of course, you can use other programming languages.

The PHP method of this script takes the local time zone (the one from the server), so it may be different to your visitors. This is why we show the time zone in this tutorial.

To begin with, as ever with any PHP script, we need to declare the PHP start tags.

  1. <?php

Now, we need to set two variables. The first one $time and the second one $timezone. These will be what the script interprets.

  1. <?php
  2. /* This sets the $time variable to the current hour in the 24 hour clock format */
  3. $time = date("H");
  4. /* Set the $timezone variable to become the current timezone */
  5. $timezone = date("e");

Now we have that step up, we need to determine our checks to find out the time and display the appropriate greeting. The first greeting will be 'good morning from $timezone'. So, let's create an IF statement to see whether the time is below 12pm and show the output.

  1. <?php
  2. /* This sets the $time variable to the current hour in the 24 hour clock format */
  3. $time = date("H");
  4. /* Set the $timezone variable to become the current timezone */
  5. $timezone = date("e");
  6. /* If the time is less than 1200 hours, show good morning */
  7. if ($time < "12") {
  8.     echo "Good morning from $timezone";
  9. }

Move on to the next page for the next steps.

Page 1 | Page 2 | Page 3 | Page 4

This tutorial is up to date as of 04 October 09. While you're here, why not check out more tutorials? You could also subscribe to our RSS Feed, or even check out our Twitter - follow us for the latest updates. For video tutorials, subscribe to our YouTube channel. Feel free to check out our blog for more updates.

 

 

Hull Design Online YouTube Channel Hull Design Online RSS

Bookmark and Share

Latest

Smoke Scene Design
Modern Bokeh Effect Realistic Snow Photoshop Layout
Create Newspaper Headlines Halloween Poster - Part 2 of 2 Halloween Poster - Part 1 of 2
Halloween Text Time Greeting Sticky Tape
Business Card Design Draw Lined Paper Amazing 3D Text
Stunning Typography Create Realistic Reflections Widescreen Border
Indented Text Effect Advanced Shadows Text Styling Tutorial
Website Status Checker Load Time Optimise Pages
Shorthand CSS Optimise Your Windows System Manage Your Passwords Safely and Securely