The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
IP Based Image
Discuss IP Based Image in the PHP Development forum on Dev Shed. IP Based Image PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 27th, 2012, 09:42 AM
|
|
Contributing User
|
|
Join Date: Sep 2011
Posts: 189
Time spent in forums: 15 h 55 m 34 sec
Reputation Power: 2
|
|
|
IP Based Image
Hi, i have a banner area on my website where i would like to display an image. I would like to display a different image in the banner area, depending on a users' location.
I have 4 different images:
01 - usa_banner.jpg (default)
02 - europe_banner.jpg
03 - uk_banner.jpg
04 - australia_banner.jpg
If a user views the site from a country outside of the top 4 areas, then i would like to display the default usa_banner.jpg image.
I have created my site using codeigniter. What is the best way to work out the IP ranges etc. Any advice on this would be greatly appreciated. Thanks in advance...
|

December 27th, 2012, 11:30 AM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
Hi,
your friend Google will tell you everything you need to know. Just search for "ip location" or "geolocation".
PHP even has an extension for this, but I don't know how it works and how good it is.
|

December 27th, 2012, 12:35 PM
|
 |
Contributing User
|
|
Join Date: Nov 2012
Location: Oxford, United Kingdom
Posts: 40

Time spent in forums: 1 Day 2 h 18 m 23 sec
Reputation Power: 1
|
|
|
If you do decide to use a 'IP To Location' API, don't do it during page requests. If for whatever reason the API fails to respond, you'll be keeping your users waiting. And that's not cool.
Do it through AJAX. Perform the page request as normal and then have JS/JQuery make an AJAX request to your server, where your server talks to the API. Or even better, if the API supports JSONP and does not require any kind of auth, do it all through the client and the API. Meaning, your server can kick back and do nothing xD
Either way, I would advise not to perform an API requests during a page request. You could end up annoying a lot of users without even realising.
|

December 27th, 2012, 01:59 PM
|
|
Contributing User
|
|
Join Date: Sep 2011
Posts: 189
Time spent in forums: 15 h 55 m 34 sec
Reputation Power: 2
|
|
|
Hi NavNav, thanks for your reply... can you elaborate on what you mean, thanks in advance
|

December 27th, 2012, 04:47 PM
|
 |
Contributing User
|
|
Join Date: Nov 2012
Location: Oxford, United Kingdom
Posts: 40

Time spent in forums: 1 Day 2 h 18 m 23 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by oo7ml Hi NavNav, thanks for your reply... can you elaborate on what you mean, thanks in advance |
Well, an 'IP To location' API is just a small web service that has access to a large DB of IP addresses and their geo location data (country, city, ect ect).
Developers can use the API by simply passing an IP address to it, and having the API return the geo data of that IP.
So we can take our visitors IP, pass it to the API and it will return the geo data for that IP (meaning, we will know where the user is based (the country and city).
There's loads of them out there. Most are free, but some may charge.
What I was saying in my previous post was that if you do use this method to trace a user by IP, don't do it during page requests.
When using a web service API, you're making HTTP requests and you're waiting for those requests to come back with a response. If the API you're requesting is running slow for whatever reason, your HTTP request will take a while to complete. So, if you make the HTTP request (talk to the API) during a page request and the API is having a bad day (running rather slow), your user will be kept waiting as the page request will not proceed until the HTTP request is complete. So you're basically having your site/app's performance depend on that API.
So, that's why you shouldn't do it. Instead, do not talk to the API during page requests but do it after the page request is complete, with JS and AJAX.
Simply have your page(s) make AJAX requests to your server from the client side (users machine). It will request a script on your server which then talks to the API (makes the appropriate HTTP requests) and returns the response. Then you can have JS change/load the specific image, based on the response.
|

December 28th, 2012, 09:04 AM
|
|
Contributing User
|
|
Join Date: Sep 2011
Posts: 189
Time spent in forums: 15 h 55 m 34 sec
Reputation Power: 2
|
|
|
Ok cool, thanks, that makes perfect sense
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|