I think I'm just missing something easy here.
If I run the API by just pasting my referral URL into my browser, it returns my local conditions.
Once I write some php around it and enter my website's URL into my browser, I get local conditions for my server's location.
What do I need to do to make sure that my website is displaying the actual local conditions?
Thanks!
If I run the API by just pasting my referral URL into my browser, it returns my local conditions.
Once I write some php around it and enter my website's URL into my browser, I get local conditions for my server's location.
What do I need to do to make sure that my website is displaying the actual local conditions?
Thanks!
- 19 Posts
- 1 Reply Like
Posted 7 years ago
- 19 Posts
- 1 Reply Like
OK... clearly this is happening because the call is being made from the Server when the php is executed.
But I'm new to this & I have no idea how to code it so that it gets the info for the viewer's machine.
Can someone just point me in the right direction, please?
Thanks.
But I'm new to this & I have no idea how to code it so that it gets the info for the viewer's machine.
Can someone just point me in the right direction, please?
Thanks.
- 19 Posts
- 1 Reply Like
Alright, trying to answer my own question.
Figured out how to query for local IP & then convert that to City & State.
I'm confused about the IP that it's returning, though.
This code tells me I'm in Tyler, Texas, which I'm not. Neither is my Server, though, so this seems like progress.
If I ask Google what my IP is, it gives me the same IP, which, apparently, is in Tyler, Texas.
If I use the Wunderground Request URL directly in my browser, though, it knows exactly where I am in California.
How are you guys doing that???
Here's the code I wrote so far:
Figured out how to query for local IP & then convert that to City & State.
I'm confused about the IP that it's returning, though.
This code tells me I'm in Tyler, Texas, which I'm not. Neither is my Server, though, so this seems like progress.
If I ask Google what my IP is, it gives me the same IP, which, apparently, is in Tyler, Texas.
If I use the Wunderground Request URL directly in my browser, though, it knows exactly where I am in California.
How are you guys doing that???
Here's the code I wrote so far:
$user_ip = $_SERVER['REMOTE_ADDR'];
$ip_string = file_get_contents("http://api.ipinfodb.com/v3/ip-city/?key=1234&ip=${user_ip}");
$location = explode(";", $ip_string);
$json_string = file_get_contents("http://api.wunderground.com/api/1234/conditions/astronomy/q/${location[8]},${location[9]}.json");
- 19 Posts
- 1 Reply Like
OK... I guess what it is returning is the Whois information, not the Geo Information. Still stuck on this one, I guess.
- 19 Posts
- 1 Reply Like
Halleluha! Apparently, it's all about the database.
This one seems to return the Geo location of the IP, not the Whois location of the IP.
http://www.geoio.com/
I'm sure there are other ones out there. Happy to hear suggestions if you have them.
So, the code becomes:
Thank you for your free service Wunderground!
Now that I have finally mastered this, please don't change with the big buyout!!! :)
This one seems to return the Geo location of the IP, not the Whois location of the IP.
http://www.geoio.com/
I'm sure there are other ones out there. Happy to hear suggestions if you have them.
So, the code becomes:
$user_ip = $_SERVER['REMOTE_ADDR'];
$geo_ip = file_get_contents("http://api.geoio.com/q.php?key=1234&qt=geoip&d=semi&q=${user_ip}");
$location = explode(";", $geo_ip);
$json_string = file_get_contents("http://api.wunderground.com/api/1234/conditions/astronomy/q/${location[4]},${location[5]}.json");
Thank you for your free service Wunderground!
Now that I have finally mastered this, please don't change with the big buyout!!! :)
Brendan Hayes, Official Rep
- 962 Posts
- 124 Reply Likes