other options besides auto ip

  • 1
  • Question
  • Updated 4 years ago
We are wanting to change the way we gather our information for displaying our weather on our site.

How can we get the users zip code via their ip address and store that into a cookie then also pass that info (zip code) that we get from their ip and pass it to the weather underground app instead of using auto ip?
Photo of Jasen Burkett

Jasen Burkett

  • 4 Posts
  • 0 Reply Likes

Posted 4 years ago

  • 1
Photo of afelicioni

afelicioni

  • 227 Posts
  • 43 Reply Likes
Unless Weather Underground has a vendor partner for returning ip geographic data for requesting devices, I'm afraid you have to integrate your project with an external source about zipcode to ip lookup.
Photo of Jasen Burkett

Jasen Burkett

  • 4 Posts
  • 0 Reply Likes
Well I already have a solution to pull in the zip code via users ip.. however I do not know how to pass that on to where I normally would place autoip.

I would like to store the info in the cookie data.
Photo of afelicioni

afelicioni

  • 227 Posts
  • 43 Reply Likes
You may need to reveal something more about your project.

Are you able to successfully query weather informations for a ZIP from your software?
Is your software already covering storage and retrieve of cookies, or you need code hints to write it?
Can you catch returned ZIP information you're available to call from existing service?
Photo of Jasen Burkett

Jasen Burkett

  • 4 Posts
  • 0 Reply Likes
Currently, we are using their auto ip feature and it works fine... however one of our editors decided that since he and another editor are getting non accurate zip codes (same city but 10 miles away from each other) that we needed antoher way to be more accurate.

So a guy from the wu suggested that we use something else other than their autoip feature.... like getting the viewers ip and then using that to get their zip code... I can do that, however I do not know how to store that info (zip code) into a cookie so when the user comes back ti will either store it if its not there and or use that info each time.

then.... how to pass that info (cookie data) to the weather undergrounds http request that currently uses the autoip function..

I hope that answers your question.
Photo of afelicioni

afelicioni

  • 227 Posts
  • 43 Reply Likes
I think the whole picture will be bound to the software or programming logic that right now is reading the client IP address used for reference, so it's a closely related to "programming something".

Since previously set cookie values are passed in HTTP request headers by clients themselves for every requested resource, server software should be aware if it needs to perform some request before outputting the resource for asked URL; I just think about cookies like it were a parameter - user don't need to type, passed in address as /resource.html?zipcode=12345
First time, as above, you would just ask for /resource.html , and here (again before outputting data) the server software would include a "Set-Cookie" response header containing the zip code value, like a "Content-Type: text/plain" is returned to the client for referencing a flat text file.

As a PHP user I know there are functions and reflected variables to set and get cookies, so this should be covered as similar approach in ASP, python, node.js, perl, you-name-it... Searching and digging sites like stackoverflow usually are useful places to discover replied solutions for programming topics like this one.

Downside (bad or good): cookies usually need to be planned having an expiry date.

so, let me write this for my reference:
1) Have a buffer, do not reply for any data at first
2) Client asked for a resource, specifying a zipcode in cookie header?
no, get the closest zipcode, using the working system
yes, just use the passed value
3) Query the weather underground for the zipcode
4) Do the needed operations with returned datas
5) Add the "Set-Cookie" in the output headers, with the zipcode value, so the same returning client already focused for a zipcode
6) Output the HTML