2017-07-19 116 views
0

我想通過用戶IP地址在url中設置國家代碼,並用國家代碼重寫和重定向index2.php在url中設置國家代碼並用國家代碼重寫它

index.php文件:

<?php 
function getLocationInfoByIp(){ 
    $client = @$_SERVER['HTTP_CLIENT_IP']; 
    $forward = @$_SERVER['HTTP_X_FORWARDED_FOR']; 
    $remote = @$_SERVER['REMOTE_ADDR']; 
    $result = array('country'=>'', 'city'=>''); 
    if(filter_var($client, FILTER_VALIDATE_IP)){ 
     $ip = $client; 
    }elseif(filter_var($forward, FILTER_VALIDATE_IP)){ 
     $ip = $forward; 
    }else{ 
     $ip = $remote; 
    } 
    $ip_data = @json_decode 
    (file_get_contents("http://www.geoplugin.net/json.gp?ip=".$ip));  
    if($ip_data && $ip_data->geoplugin_countryName != null){ 
     $result['country'] = $ip_data->geoplugin_countryCode; 
    } 
    return $result; 
}  
$result = getLocationInfoByIp($_SERVER['REMOTE_ADDR']);  
$cont = $result['country'];  
?> 

index2.php文件:

<h1>HELLO WORLD !</h1> 

我怎麼可以重寫URL和index2.php重定向?

當重定向我的URL應該看起來像orchidkart.com/IN/index2.php

回答

1

嘗試在URL

header('Location: index2.php?country='.$cont); 

路徑或完整路徑

header('Location: http://localhost/directory/index2.php?country='.$cont); 

或解析動態變量

header('Location: http://localhost/directory/$cont/index2.php'); 
+0

你能送我.htacces s文件關於我的代碼.. ?? ..請... –

+0

嘿theres任何一個....幫助我 –