samoi Posted November 13, 2008 Share Posted November 13, 2008 Hello guys How are you all? I just want to know the idea of scripting a php script so that it determine a US user and display the "voting pools" for example. and UK users to display some other ads which is concerning the UK, and the overseas users I want to to display a regular ads, can that be happened? I'm just wondering, and would love to know what kind of functions should I use if this works. Link to comment https://forums.phpfreaks.com/topic/132636-how-to-display-contents-for-overseas-costumers-and-us-costumers-and-uk-costumer/ Share on other sites More sharing options...
flyhoney Posted November 13, 2008 Share Posted November 13, 2008 I think you will either need to use a database or a service. I found this thread on the subject: http://www.daniweb.com/forums/thread45179.html They talk about a script that could supposedly do what you want to do: <?php function countryCityFromIP($ipAddr) { //function to find <strong class="highlight">country</strong> and city from <strong class="highlight">IP</strong> <strong class="highlight">address</strong> //Developed <strong class="highlight">by</strong> Roshan Bhattarai [url]http://roshanbh.com.np[/url] //verify the <strong class="highlight">IP</strong> <strong class="highlight">address</strong> 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 <strong class="highlight">country</strong> name inside the node <countryName> and </countryName> preg_match("@<countryName>(.*?)</countryName>@si",$xml,$matches); //assign the <strong class="highlight">country</strong> name to the $ipDetail array $ipDetail['country']=$matches[1]; //get the <strong class="highlight">country</strong> name inside the node <countryName> and </countryName> preg_match("@<countryAbbrev>(.*?)</countryAbbrev>@si",$xml,$cc_match); $ipDetail['country_code']=$cc_match[1]; //assing the <strong class="highlight">country</strong> code to array //return the array containing city, <strong class="highlight">country</strong> and <strong class="highlight">country</strong> code return $ipDetail; } ?> Link to comment https://forums.phpfreaks.com/topic/132636-how-to-display-contents-for-overseas-costumers-and-us-costumers-and-uk-costumer/#findComment-689739 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.