Fluoresce Posted September 5, 2010 Share Posted September 5, 2010 Hi, guys. I want to present different ads to visitors in different countries. For example, if a visitor is in Australia, I want him/her to see a different ad from, say, a visitor from the UK. Can this kind of thing be done with PHP? If so, will installing such a code slow down my site? Any help will be appreciated very much. Quote Link to comment Share on other sites More sharing options...
freeloader Posted September 5, 2010 Share Posted September 5, 2010 Sure this is possible. It would require an extensive database though, so it might slow down your site a bit. There should be plenty of examples on this on the web if you google it. Quote Link to comment Share on other sites More sharing options...
mattheww Posted September 5, 2010 Share Posted September 5, 2010 Yeah, you can do it by getting a user's IP and from that you can work out what country they are from, and also what city, I think? Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted September 5, 2010 Share Posted September 5, 2010 There is a simple way to do it, without installing anything but it can be slow on occassions. Look at this <?PHP function getLocation($string,$oTag,$cTag) { // Get position of openingTag $start = strpos($string, $oTag); // Get position of endingTag $end = strpos($string, $cTag, ($start + strlen($oTag))); // Remove everything before openingTag $start = ($start + strlen($oTag)); // Remove everything after endingTag $end = ($end - $start); // Return the location of the IP return substr($string, $start, $end); } // Get the visitors IP Address $ipAddress = $_SERVER['REMOTE_ADDR']; // Look up the visitors IP Address for location $ipLocation = file_get_contents('http://api.hostip.info/get_html.php?ip='.$ipAddress.''); // Filter returned string to get the country of the IP $ipLocation = getLocation($ipLocation,'(',')'); // Display the location of the visitors IP echo $ipLocation; ?> Thanks should do it for, but it is not 100% correct all of the time. Regards, Paul. Quote Link to comment Share on other sites More sharing options...
Fluoresce Posted September 5, 2010 Author Share Posted September 5, 2010 Thanks, Paul! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.