Good morning/good evening PHP function

How can I get php coding of good morning/good evening script when a user enter the site then it is show greeting.

A very simple solution, but a solution nonetheless. Take into account the different time zones of people around the world though. You might be looking for a more advanced solution if you want to change the timezone for each user, but this will give you an idea.

<?php

function greeting(){

    $timeOfDay = date('a');
    if($timeOfDay == 'am'){
        return 'Good morning, welcome to our site';
    }else{
        return 'Good afternoon, welcome to our site';
    }

}

echo $timeOfDay;

?>

Like bit10101 says, do you want to say “Good morning” depending on where the server is or where the user is?

This tut might help you grapple with some of the issues: http://www.onlineaspect.com/2007/06/08/auto-detect-a-time-zone-with-javascript/

I’m always a sucker for GeoIP: http://php.net/manual/en/book.geoip.php

GeoIP won’t be as accurate as javascript which uses the user’s system clock and seems like overkill for this!

I don’t feel that’s overkill at all. Javascript can be just as inaccurate as GeoIP. Your counting on their clock to be set correctly, as well as the fact that Javascript can be turned off. All depends on its application and the necessity of the data.

On my shared server, geoIP functions don’t work, presumably they need activating somewhere, but I don’t have that kind of access. So, I would be restricted to javascript, in which case this might be helpful:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=windows-1250">
  <title></title>

<script>
function getTime() {
    var dd = new Date();
    var hh = dd.getHours();

    if(hh > 11){
    document.write("Good afternoon");
    }else{
    document.write("Good morning");
    }

}
 </script>
  </head>
  <body>
  <p><button onclick ="getTime()">Click for greeting based on time of local machine</button></p>
  </body>
</html>

GeoIP is a PECL extension, so yes it would need installed on the server running it.