>really simple one -
>
>does someone have a bit of code that will variously display 'good morning', 
>'good afternoon', 'good evening' based on the current time?
>
>good morning from london,

My time or your time?

If you want it to be "server" time, use this:

<?php
  $hour = date('H');
  if ($hour < 12){
    $greet = 'morning';
  }
  elseif ($hour < 17){
    $greet = 'afternoon';
  }
  else{
    $greet = 'evening';
  }
  echo "good $greet from london<BR>\n";
?>

If you want it based on *THEIR* time, you have to use JavaScript to send
yourself the time set on their computer's clock on the previous page, and
then greet them...  Which means they'll have already seen some kind of page,
or at least a "flash" as the first page reloaded...

Something like this:

<?php
  if (!isset($client_time)){
?>
<HTML>
<HEAD><META TYPE=HTTP-EQUIV
CONTENT="0;URL=<?=$_ENV['PHP_SELF']?>?client_time=<SCRIPT
LANGUAGE=JavaScript>
  document.write(date('H'));
</SCRIPT>"></HEAD>
</HTML>
<?php
  }
  else{
    $hour = $_GET['client_time'];
    # Same as above
  }
?>

There are a zillion things that can go wrong with this second choice:
1. User didn't set their clock properly
2. User has JavaScript "off" or broken
3. My JavaScript is almost for sure wrong (sorry)
.
.
.

You could also have "User Profiles" and one of the endless questions you ask
them to fill in could be time zone, and then you could calculate their local
time when they come back to visit, based on the server time and their time
zone.

Of course, if they travel, you're just going to confuse them, since they'll
know it's not 'evening' where your server is, nor where they are now...

Bottom Line:
Since it's the WORLD wide web, maybe trying to be 'smart' and say the right
thing to them based on time of day isn't such a Good Idea in the first
place.

-- 
Like Music?  http://l-i-e.com/artists.htm


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to