I'm building a new website and need to know what country is the visitor from so I can dynamically display the right content for them (ie France - french content etc). I know it's possible, many sites do it. I'd like to do it using PHP if possible. Any ideas? Thanks!
<?php $ip = "xx.xxx.xxx.xx"; $file = file_get_contents("http://www.melissadata.com/lookups/iplocation.asp?ipaddress=" . $ip); preg_match('^<tr><td align="right">Country</td><td><b>([A-Z]+)</b></td></tr>^',$file , $country); $country = $country[1]; if(empty($country)) { echo "Invalid IP"; }else{ echo ucfirst(strtolower($country)); } ?> PHP: Hope this helps you.
in addition to what NuLLByTe said you can change $ip = "xx.xxx.xxx.xx"; to $ip = $_SERVER['REMOTE_ADDR'];
I got this error when trying to import the database: Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 8216437 bytes) in URL/import.php on line 101 any ideas?
To resolve the php error you get: For those of you who use shared hosting the quick solution would be to add a line in .htaccess file located at your root folder, or you may need to create a file called php.ini in your hosting account root. This is the command: php_value memory_limit 24M here 24M is an example and most of the times this is enough to get your site back, contact your host support if this doesnt work. First step for this is to locate your php.ini file in the server and to see what is the memory limit (this is shown in the error message). Create a file with the below code and name it something like “test.phpâ€