Vicky Jane Vicky Jane - 18 days ago 5
PHP Question

How do I get this done

The code below is meant to show my visitors something like "Good Morning, Today is ------ and the time is -----"

But I keep getting "Welcome" instead of the main greetings

<?php
$hour = date ("G");
$minute = date ("i");
$second = date ("s");
$msg = " Today is " . date ("l, M. d, Y.") . " And the time is " . date ("g:i a");

if ($hour = 00 && $hour <= 9 && $minute <= 59 && $second <= 59)
{ $greet = "Good Morning,"; }

else {

if ($hour >= 10 && $hour <= 11 && $minute <= 59 && $second <= 59)
{ $greet = "Good Day,"; }

if ($hour >= 12 && $hour <= 15 && $minute <= 59 && $second <= 59)
{ $greet = "Good Afternoon,"; }

if ($hour >= 16 && $hour <= 23 && $minute <= 59 && $second <= 59)
{ $greet = "Good Evening,"; }

else { $greet = "Welcome,"; }
}
echo $greet.$msg;
?>


Any idea on how to get this done?

How do I get timezones of my visitors automatically using php. My server's default timezone is Lagos/Africa.
I want the code above to show my visitors their local time and date.

Any ideas?

Answer

Your problem is here

 if ($hour = 00 && $hour <= 9 && $minute <= 59 && $second <= 59) 

this way you assign 00 to $hour and all the other condition fails

you need

if ($hour == 0 && $hour <= 9 && $minute <= 59 && $second <= 59)