Link to home
Start Free TrialLog in
Avatar of phaygarth
phaygarth

asked on

Display different URL/text to visitor based on their local time.

I would like to display a different, clickable URL to my website visitors depending on their local time.

So for example, if they visit my site and their local time is between 7pm to 6am, the page should display 'abc.com'.

Whereas if they visit between 6am to 7pm, I would like to display 'xyz.com' to them.

Is this possible and how would I go about it please?

Thanks
Avatar of Ray
Ray
Flag of Canada image

Time zone information of the browser is not part of the HTTP spec, so you can't just get it from a header.  You'll probably need to get geo info from their IP.

Required
http://www.maxmind.com/download/geoip/api/php/php-latest.tar.gz
http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz

Get visitor local time, sunrise and sunset time by IP with MaxMind GeoIP and PHP
http://snippets.khromov.se/get-visitor-local-time-sunrise-and-sunset-time-by-ip-with-maxmind-geoip-and-php/
Just instantiate a javascript date object in your pages code.

now = new Date();
hour = now.getHours();
See Practical Application #8 in this article:
https://www.experts-exchange.com/Programming/Languages/Scripting/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

Unless you really need to keep this information in PHP, the best answer is probably something like this:

1. Send "Good morning" and "Good afternoon" messages in hidden divs
2. Detect the time of day
3. Show the div that is appropriate
ASKER CERTIFIED SOLUTION
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of phaygarth
phaygarth

ASKER

That worked perfectly, thank you.