www.webdeveloper.com
Results 1 to 5 of 5

Thread: Client side date to a PHP script for DB query

  1. #1
    Join Date
    Jun 2014
    Posts
    2

    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.

    Pradeep.

  2. #2
    Join Date
    May 2014
    Posts
    75
    If you want a full php solution I'd have a look at this site:

    http://ipinfodb.com/

    You can see some code examples here:

    http://ipinfodb.com/ip_location_api.php

    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.

  3. #3
    Join Date
    Jun 2014
    Posts
    2
    Quote Originally Posted by Gravy View Post
    If you want a full php solution I'd have a look at this site:

    http://ipinfodb.com/

    You can see some code examples here:

    http://ipinfodb.com/ip_location_api.php

    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.
    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?

    Thank you.

  4. #4
    Join Date
    Jun 2014
    Posts
    27
    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.

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,330
    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

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles