Hello , i've some banner ads ( banner1.png , banner2.png , banner3.png ) i need to show banner1 for US & CA traffic and banner2 for UK and banner3 for rest of the world traffic . Please how i can do that in php ? can anyone help me with the code ? thank
function countryCityFromIP($ipAddr) { //function to find country and city from IP address //Developed by Roshan Bhattarai http://roshanbh.com.np //verify the IP address for the ip2long($ipAddr)== -1 || ip2long($ipAddr) === false ? trigger_error("Invalid IP", E_USER_ERROR) : ""; $ipDetail=array(); //initialize a blank array //get the XML result from hostip.info $xml = file_get_contents("http://api.hostip.info/?ip=".$ipAddr); //get the city name inside the node <gml:name> and </gml:name> preg_match("@<Hostip>(\s)*<gml:name>(.*?)</gml:name>@si",$xml,$match); //assing the city name to the array $ipDetail['city']=$match[2]; //get the country name inside the node <countryName> and </countryName> preg_match("@<countryName>(.*?)</countryName>@si",$xml,$matches); //assign the country name to the $ipDetail array $ipDetail['country']=$matches[1]; //get the country name inside the node <countryName> and </countryName> preg_match("@<countryAbbrev>(.*?)</countryAbbrev>@si",$xml,$cc_match); $ipDetail['country_code']=$cc_match[1]; //assing the country code to array //return the array containing city, country and country code return $ipDetail; } PHP: Source
For this you would use GEO-Targeting. There are tons of good examples out there, unfortunately I cannot post any links yet. First step is getting a GEO database, I would recommend GEOLITE City from maxmind. Same company has a PHP API for using these databases and then it should be very simple switch statement where you want to show a specific banner if you were trying to add the code directly into a page. Another option would be to use Open X which has a Geo-Targeting plug-in.
thanks for fast reply , i've installed the GEOIP on my dedicated server and configured it and it's working well after some small code for test . i will try ssmm987 code and also i will googling on any other code , still need more replys and info to make good things thanks