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
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
Just instantiate a javascript date object in your pages code.
now = new Date();
hour = now.getHours();
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That worked perfectly, thank you.
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/