Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Tuesday, 7 February 2012

Tracking your visitors' location with PHP


If you are in a situation that you need to show different content to your visitors depending on their location, an easy way to do it is with #PHP using MaxMind's IP database. MaxMind is offering commercial database of locations for IP addresses, but they also have a free product GeoLite Country http://bit.ly/yoPj7C

It is a downloadable data file (MaxMind provides monthly updates) that you can query through PHP or other languages or even an Apache module (MaxMind offers libraries http://bit.ly/yMsTP8 for several languages). If you don't like the idea of downloading a file every month there are other alternatives like GeoPlugin.com and IpInfoDB.com but I opted to skip the part of making network requests to a third-party server.

I've cooked up an example of querying the the data file and keeping the information on a cookie so that the total number of queries is smaller. Check it out here http://bit.ly/wBm7bm

Wednesday, 26 October 2011

New #PHP book from Sitepoint, ordered, looking forward to the weekend to read it...

New #PHP book from Sitepoint, ordered, looking forward to the weekend to read it :)


Embedded Link





Home - PHP Master: Write Cutting-Edge Code
Sharp, sure-fire techniques guaranteed to take your PHP skills to the next level

Thursday, 8 September 2011

How to read pages with PHP and Diffbot, a visually learning robot

Say you want to copy Facebook's any-page-on-the-web sharing feature where a title, photo and part of the content is automagically presented to the user. Or you want to build yet another news reading service (after you finished building your geo-location group-chat app ;)). You can now do this with Diffbot.

Friday, 29 July 2011

Fixing UTF encoding in AJAX requests on Internet Explorer

The legendary status of Internet Explorer for being special among all browsers was reminded to me when I discovered that sending a variable with non-latin character in a GET request over AJAX is apparently too troubling for IE. The result is that characters in greek are either transformed to latin ones or just disappear. This was all in a simple call like this:
[code lang="js"]$("#search_result").load("/ajaxsearch/&id=$id&f="+what);[/code]
(Where [i]what[/i] was the value of an input used in a AJAX-powered "quick search" form. Calling the same URL on a normal (non-AJAX) request everything worked perfectly.
The solution (after trying for hours to figure out what kind of transformation IE was doing on the value of the string), was simple enough: send it via POST
[code lang="js"]
$.post("/ajaxsearch/&id=$id&",{ f: what },
function(returned_data) {
$("#search_result").html(returned_data);
});[/code]
I guess since it was a input box, I should have treated the call as a form and used POST from the start, right?