ActiveState Code

Recipe 208103: Making Interactive Welcome Text


In usually we say welcome in our page with simple like "welcome user" adn etc but I think if we can say like "Hello, good morning user" its more interactive say. It can be done with simple using date() or time function in php.

PHP
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
function sayhello(){
 $hours=date("G")+0;
 ### you can set own criteria in your country
 ### whats time we must say good morning and etc
 if( $hours>=0 &&  $hours<=14) $hellowords="Good Morning";
 elseif( $hours<=18) $hellowords="Good Afternoon";
 else $hellowords="Good Night";
 return $hellowords;
}


### calling in your script with
### echo "Hello user, ".sayhello();

Sign in to comment