Reply LinkBack Thread Tools Search this Thread
Old 13-12-2007, 12:05   #21 (permalink)
Shiro
shiro
 
Shiro's Avatar
 
Join Date: Aug 2007
Location: Yokohama, Japan
Posts: 2,610
Is that all your code? Are you sure the problem isn't something coming before that - forgotten bracket or semi-colon or something?
  Reply With Quote
Old 13-12-2007, 22:25   #22 (permalink)
mgpwr
with a hint of lemon
 
mgpwr's Avatar
 
Join Date: Aug 2006
Location: Sheffield
Posts: 489
yerp that all of it...
__________________
Online portfolio: mgpwr.co.uk
  Reply With Quote
Old 14-12-2007, 03:41   #23 (permalink)
Shiro
shiro
 
Shiro's Avatar
 
Join Date: Aug 2007
Location: Yokohama, Japan
Posts: 2,610
It took me a bit to find it, but I think its because your opening php tag is incorrect. it should open with

<?php

You opened it with

<?

Try that.
  Reply With Quote
Old 14-12-2007, 11:16   #24 (permalink)
mgpwr
with a hint of lemon
 
mgpwr's Avatar
 
Join Date: Aug 2006
Location: Sheffield
Posts: 489
Fatal error: Call to undefined function: array() in mgpwr.co.uk/greeting.php on line 6

you try it on yours, cos i'm stumped!
__________________
Online portfolio: mgpwr.co.uk
  Reply With Quote
Old 14-12-2007, 11:27   #25 (permalink)
pgo
Senior Member
 
Join Date: Jan 2005
Posts: 12,340
echo $message(date("G"));

Should be...

echo $message[date("G")];

That's the only problem I had when I ran it on my dev box. Even with error reporting set to E_ALL.

If that doesn't work, you've made a mistake - left out a quote or a comma or a bracket or something somewhere. Or try capitalizing the word Array (I often see it used that way).
  Reply With Quote
Old 14-12-2007, 11:29   #26 (permalink)
datahound
Spare Parts
 
datahound's Avatar
 
Join Date: Jan 2005
Location: Bracknell Forest
Posts: 4,962
echo $message[date("G")];
__________________
  Reply With Quote
Old 14-12-2007, 11:29   #27 (permalink)
datahound
Spare Parts
 
datahound's Avatar
 
Join Date: Jan 2005
Location: Bracknell Forest
Posts: 4,962
jinx
__________________
  Reply With Quote
Old 14-12-2007, 11:31   #28 (permalink)
pgo
Senior Member
 
Join Date: Jan 2005
Posts: 12,340
haha
  Reply With Quote
Old 14-12-2007, 11:38   #29 (permalink)
mgpwr
with a hint of lemon
 
mgpwr's Avatar
 
Join Date: Aug 2006
Location: Sheffield
Posts: 489
Yup, its working, thanks..
__________________
Online portfolio: mgpwr.co.uk
  Reply With Quote
Old 15-12-2007, 07:42   #30 (permalink)
mgpwr
with a hint of lemon
 
mgpwr's Avatar
 
Join Date: Aug 2006
Location: Sheffield
Posts: 489
Quote:
Originally Posted by haku
Sorry, I just realized I referenced a script that I didn't include in my post. Try this:

Code:
<?php function curPageName() { return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1); } if(!isset($_COOKIE['offset'])) { ?> <script type="text/javascript"> { var now = new Date(); var client_offset = now.getTimezoneOffset() * 60; document.cookie = 'offset=' + client_offset; window.location=("<?php echo curPageName(); ?>"); } </script> <?php } ?>


I have added this just above the script i am using to say the quotes depending on the time, how will i know if it is working, i have changed the time zone on my laptop and it still stays with the same message.. so err how would i test it is working?
__________________
Online portfolio: mgpwr.co.uk
  Reply With Quote
Old 16-12-2007, 01:31   #31 (permalink)
Shiro
shiro
 
Shiro's Avatar
 
Join Date: Aug 2007
Location: Yokohama, Japan
Posts: 2,610
Add a link to a page that outputs the time and get some of us to check it for you. We are in many different timezones.

I tried by checking myself in my timezone, and having my buddy in the states check in his. We were both in different timezones that the server, and both were correct. But truth be told, that was the extent of my checking, so there is the possibility that the script is flawed and that it doesn't work!
  Reply With Quote
Old 16-12-2007, 05:30   #32 (permalink)
Bill Posters
trouble free and loverlee
 
Join Date: Mar 2003
Location: YooKay
Posts: 2,933
Imho™…

For such a non-critical thing, javascript would be the better option.
Its date functions work according to the date on the user's machine. So, presuming the date on their machine is set correctly, it'll automatically be a localised time-based greeting.

JavaScript Date Object Reference

You could have a default greeting in the markup and use js to customise it to a localised, time-based greeting.

(rough) e.g.
Code:
window.onload = init; function init() { if (!document.getElementById('greeting')) return; var greetingEl = document.getElementById('greeting'); var d = new Date(); var hour = d.getHours(); var greetingMsg = ''; if (hour < 12) { greetingMsg = 'Good morning!'; } if (hour >= 12 && hour < 19) { greetingMsg = 'Good afternoon!'; } if (hour >= 19) { greetingMsg = 'Good evening!'; } greetingEl.firstChild.nodeValue = greetingMsg; }
Code:
<p id="greeting">Welcome!</p>
  Reply With Quote
Old 16-12-2007, 06:40   #33 (permalink)
mgpwr
with a hint of lemon
 
mgpwr's Avatar
 
Join Date: Aug 2006
Location: Sheffield
Posts: 489
__________________
Online portfolio: mgpwr.co.uk
  Reply With Quote
Old 16-12-2007, 06:47   #34 (permalink)
Shiro
shiro
 
Shiro's Avatar
 
Join Date: Aug 2007
Location: Yokohama, Japan
Posts: 2,610
Well, whatever you have done, it didn't work, as the greeting is telling me good morning, but it is evening where I am.

Actually Bill Posters is entirely correct in what he is saying. His code is much less bulky and easier to use than what I posted. What I forgot until I read his post is that I created that code to show all times, not just the current time, in the user's timezone (for example times on posts on a forum). Since you can't get the code I gave you to work, I would suggest adding his code to your site, as it should work as is.
  Reply With Quote
Old 17-12-2007, 00:56   #35 (permalink)
pgo
Senior Member
 
Join Date: Jan 2005
Posts: 12,340
Bill to the rescue again.

It's not working here either. It's 11:56PM and showing "Good morning!".
  Reply With Quote
Old 17-12-2007, 13:19   #36 (permalink)
MikeMackay
Everything is fine.
 
MikeMackay's Avatar
 
Join Date: Feb 2005
Location: Witham & London
Posts: 828
Send a message via MSN to MikeMackay Send a message via Skype™ to MikeMackay
I definitely agree with Bill. Since you were going using use JavaScript with your PHP code to retrieve the users timezone for the calculation, you may as well use an entire JavaScript solution instead.

Instead of using the old 'document.write' method, Bill has given the best solution using the DOM to produce the greeting. This also provides a decent fall back if the user has JavaScript turned off; the visitor will simply see the original 'Welcome' message as opposed to the customized greeting which is better than displaying an incorrect time message, or worse case scenario, nothing at all.

Just my 2 cents

- Mike
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8