Client side date to a PHP script for DB query
I have a web server running in PST. This displays events based on the date on the landing page, all done in PHP scripts.
As a result of this set up, people in other time zones (Europe and Asia mainly) are getting stale information.
So, I would like to modify the PHP query statement to use the client side date. I find that I have to use Java to extract the date from the (client) browser and pass that along to the PHP script to query the underlying DB.
Has anyone done this sort of thing? Can I be given some help on how to accomplish this?
Thank you in advance.
If you want a full php solution I'd have a look at this site:
You can see some code examples here:
Not that your sever will need to communicate with their server and should store the data in a cookie so only 1 request is made per user, not per page view.
Otherwise you're really just stuck with JS.
Remember, that anything that comes from the browser can't be trusted. Including this data in the cookies. The user could always try and change it to put bad data in a DB or anything, so always be sure to check data server-side.
Originally Posted by Gravy
Thank you for the response. This is in the right direction. However, I do not need that complicated a solution. Furthermore, I agree with you on not trusting user input or the readings from the client side, however, this is to display events (birthdays and weddings and death anniversaries) for that given date. So, if incorrect information is displayed, then that would be due to the incorrect settings on the client side computer. I can live with that.
I like the cookie idea, to reduce the constant checking. Any other thoughts? Anyone?
A suggestion from myside is to have the date as it is but determine the location of the user. With the location give the time in their time. What i mean add or sub the time to make the time zone of user.
The only two methods I've used are the IP-to-location approach mentioned above, and simply having the user specify their time zone* (typically only on sites where the user creates an account). You can merge the two together: start by making your best guess based on IP (which can be wrong at times, especially if they're coming through a proxy server), and provide an option for them to change the "guess" to what they actually want displayed (which you can then save in the DB for logged in users, or a long-duration cookie otherwise).
* There are some nifty image-based TZ selectors out there that make it pretty painless on the client-side.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
How to Ask Questions the Smart Way
(not affiliated with this site, but well worth reading)
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)