GEOIP Best practice

Discussion in 'PHP' started by gigamike, Oct 18, 2006.

  1. #1
    Hi Guys,

    i hope i can get your opinion. I have a site and i setup a geoip. i have a table of given IP range for a given country. Now my question is i setup a small script that display the Country of a certain user. and everytime the user goes to another page (other .php files), i query on the geoip table.

    So im planning to store the Country information per user log instead of querying the IP looking for the designated country.

    what do you think is better?

    Thanks,

    gigamike
     
    gigamike, Oct 18, 2006 IP
  2. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #2
    There's no need to query it on each page view, it's a waste of processing time. The IP won't change and the country won't change between clicks (unless they're on a plane, but screw them).

    I store the results in a session or cookie so even when they come back later, I don't have to query it again.
     
    T0PS3O, Oct 18, 2006 IP
  3. gigamike

    gigamike Active Member

    Messages:
    165
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    hi T0PS3O,

    thanks for the immediate reply

     
    gigamike, Oct 18, 2006 IP
  4. idotcom

    idotcom Well-Known Member

    Messages:
    522
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    108
    #4
    I also use geo to locate user country, state, city. But, on the first page view, the query will obtain the data and store it in a month long cookie.
     
    idotcom, Oct 18, 2006 IP
  5. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #5
    You can use sessions instead of cookies and I think will suit better for this purpose. What if someone has cookies disabled?
    Either you will end up sending a query to the DB again and again or display messages which are not Geo targetted...
    Bye :)
     
    JEET, Oct 18, 2006 IP
  6. idotcom

    idotcom Well-Known Member

    Messages:
    522
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    108
    #6
    All true...

    For me, I think it's a small percentage of disabled cookie users. Also, I think sessions are best for logins. Some people cant control how long sessions last. So if it were the default 24 minute sessions (I think its 24 min for php), then every time they leave and come back... you know.

    For this... I say cookies all the way.
     
    idotcom, Oct 18, 2006 IP