webtuto Posted November 11, 2008 Share Posted November 11, 2008 hey everyone i used this code to know if the visitor is from MOROCCO (a country) to redirect him to the link index.php?l=ar and if he is not from morocco i want him to go to this link index.php?l=eng so i used the code below //if visitor is from morocco $IPaddress=$REMOTE_ADDR; $two_letter_country_code=iptocountry($IPaddress); function iptocountry($ip) { $numbers = preg_split( "/\./", $ip); include("ip_files/ip_database.php"); $code=($numbers[0] * 16777216) + ($numbers[1] * 65536) + ($numbers[2] * 256) + ($numbers[3]); foreach($ranges as $key => $value){ if($key<=$code){ if($ranges[$key][0]>=$code){$two_letter_country_code=$ranges[$key][1];break;} } } if ($two_letter_country_code==""){$two_letter_country_code="unkown";} return $two_letter_country_code; } if ($two_letter_country_code=="MA"){ echo "<meta http-equiv='refresh' content='0;url=index.php?l=ar'>"; }else{ echo "<meta http-equiv='refresh' content='0;url=index.php?l=eng'>"; die(); } but when i test it , the page start refreshing again and again , non stop why? Quote Link to comment https://forums.phpfreaks.com/topic/132225-page-keep-refreshing-in-my-ip-adresses-script-need-help/ Share on other sites More sharing options...
DeanWhitehouse Posted November 11, 2008 Share Posted November 11, 2008 That is outdated now $IPaddress=$REMOTE_ADDR; Should be $IPaddress=$_SERVER['REMOTE_ADDR']; Quote Link to comment https://forums.phpfreaks.com/topic/132225-page-keep-refreshing-in-my-ip-adresses-script-need-help/#findComment-687326 Share on other sites More sharing options...
webtuto Posted November 11, 2008 Author Share Posted November 11, 2008 ok but the problem is still going on Quote Link to comment https://forums.phpfreaks.com/topic/132225-page-keep-refreshing-in-my-ip-adresses-script-need-help/#findComment-687656 Share on other sites More sharing options...
Pioden Posted November 11, 2008 Share Posted November 11, 2008 if ($two_letter_country_code=="MA"){ echo "<meta http-equiv='refresh' content='0;url=index.php?l=ar'>"; exit(); }else{ echo "<meta http-equiv='refresh' content='0;url=index.php?l=eng'>"; exit(); } Maybe the lack of exit (or die) after the if statement means you got into a loop? The rest of the code looks OK. Quote Link to comment https://forums.phpfreaks.com/topic/132225-page-keep-refreshing-in-my-ip-adresses-script-need-help/#findComment-687659 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.