imperium2335 Posted April 9, 2009 Share Posted April 9, 2009 Hi, How would I get ads to display to all countries except for the two I want blocked? I know you can block with .htaccess but this is more about including a file (the html with the ads) if the user is not from "banned country x || y". I've got all the IP combinations for the two countries i want to block. What are your thoughts? Much appreciated! Link to comment https://forums.phpfreaks.com/topic/153298-only-let-page-element-display-to-certain-countries/ Share on other sites More sharing options...
redarrow Posted April 9, 2009 Share Posted April 9, 2009 <?php 1. function countryCityFromIP($ipAddr) 2. { 3. //function to find country and city from IP address 4. //Developed by Roshan Bhattarai [url]http://roshanbh.com.np[/url] 5. 6. //verify the IP address for the 7. ip2long($ipAddr)== -1 || ip2long($ipAddr) === false ? trigger_error("Invalid IP", E_USER_ERROR) : ""; 8. $ipDetail=array(); //initialize a blank array 9. 10. //get the XML result from hostip.info 11. $xml = file_get_contents("http://api.hostip.info/?ip=".$ipAddr); 12. 13. //get the city name inside the node <gml:name> and </gml:name> 14. preg_match("@<Hostip>(\s)*<gml:name>(.*?)</gml:name>@si",$xml,$match); 15. 16. //assing the city name to the array 17. $ipDetail['city']=$match[2]; 18. 19. //get the country name inside the node <countryName> and </countryName> 20. preg_match("@<countryName>(.*?)</countryName>@si",$xml,$matches); 21. 22. //assign the country name to the $ipDetail array 23. $ipDetail['country']=$matches[1]; 24. 25. //get the country name inside the node <countryName> and </countryName> 26. preg_match("@<countryAbbrev>(.*?)</countryAbbrev>@si",$xml,$cc_match); 27. $ipDetail['country_code']=$cc_match[1]; //assing the country code to array 28. 29. //return the array containing city, country and country code 30. return $ipDetail; 31. 32. } ?> Link to comment https://forums.phpfreaks.com/topic/153298-only-let-page-element-display-to-certain-countries/#findComment-805416 Share on other sites More sharing options...
imperium2335 Posted April 9, 2009 Author Share Posted April 9, 2009 Just out of interest, I see your retrieving data from another site. Is it possible to do the same sort of thing for PageRank? E.g. a bit of code that can retrieve the page rank of a given url? Cheers. Link to comment https://forums.phpfreaks.com/topic/153298-only-let-page-element-display-to-certain-countries/#findComment-805457 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.