2017-07-19 112 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任何一个....帮助我 –