gtatler 0 Newbie Poster

Indeed it is based on the server time, as the date() funciton is a PHP function and therefore happens at run time on the server before the page is ever delivered to the user. For a browser based local to user solution, JavaScript would make more sense.

I am now using the following :-

<!-- script to display greeting -->
<script language="JavaScript"><!--
var Greeting = "Hello. ";
var Today = new Date();
var CurrentHour = Today.getHours();
if (CurrentHour < 12) { Greeting = "Good Morning. "; }
if (CurrentHour >= 12 && CurrentHour < 17) { Greeting = "Good Afternoon. "; } if (CurrentHour >= 17) { Greeting = "Good Evening. "; } document.write(Greeting); //--></script><noscript>Hello. </noscript>
<!-- end of greeting script -->

<!-- script to display full date -->
<script language="JavaScript">
var Today = new Date();
var Days = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var Months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var Year = Today.getYear();
if (Year < 1000) { Year += 1900; }
var Day = Today.getDate();
var DateEnding = "th";
if (Day == 1 || Day == 21 || Day == 31) { DateEnding = "st"; }
else if (Day == 2 || Day == 22) { DateEnding = "nd"; }
else if (Day == 3 || Day == 23) { DateEnding = "rd"; }
document.write( Days[Today.getDay()] + " " + Day + DateEnding + " " + Months[Today.getMonth()] + " …

gtatler 0 Newbie Poster

Just one question.

Does this coding use the server time or the local PC time ?

I have tested it out this morning and the greeting changes at noon, but if I change my PC clock to 17:05 it does not change the greeting, and on altering the code to display $numeric_date it shows 12 ! And yes, I HAVE refreshed my browers - several times.

If it uses the server time then I can understand this as my ISP server is located in the UK, but if it is supposed to use the local PC time then I can't understand it.

Any comments or suggestions ?

gtatler 0 Newbie Poster

Now that you understand what goes on in the script, put the script in its' entirety into a file of its' own named welcome_script.php. Now go to whatever place in your code that you want the greeting to be shown and include welcome_script.php. If you don't know anything about includes, check out my tutorial on includes here. If you don't want to learn about includes, or just plain don't want to include it (both of which I don't know why you wouldn't want to do), then you can just insert the script itself into the part of your website code where you want it to be displayed.

Smashing !

I use the Etomite content management system on my web site which enables one to insert snippets of code into the database and call them on any web page (or template), and I have incorporated this coding into my site template.

For any other visitors who use Etomite here's what to do.

Copy the CODING (without the <?php and ?>) into a new snippet in site manager, naming it (say) Greeting.

Change the line
echo "$welcome_string";
to
return "$welcome_string";

and save the file.

Wherever you want the greeting to be displayed call the snippet by [[Greeting]] - and there you are !