重定向php用户从香港或西班牙到另一个站点

时间:2022-11-29 23:20:52

I am trying to visiting my site to another sub site for visitors from * or spain. I am trying to use the following code to redirect visitors based on IP, but it doesn't seem to be working.

我正试图访问我的网站到另一个子网站,为来自香港或西班牙的访客。我试图使用以下代码基于IP重定向访问者,但它似乎没有工作。

if($ipnum >= ip2long('2.20.179.0') && $ipnum <= ip2long('2.20.179.255')){
    header('Location: http://www.example.com/es/');
}
elseif($ipnum >= ip2long('14.0.128.0') && $ipnum <= ip2long('14.0.255.255')){
    header('Location: http://www.example.com/hk/');
}

Kindly help with corrections or modifications.

请帮助纠正或修改。

1 个解决方案

#1


0  

You can try using 3rd party API which responses you the country of visitor.

您可以尝试使用第三方API来回复您访问者的国家/地区。

Try using this API :

尝试使用此API:

http://www.telize.com/geoip/2.20.179.0 (http://www.telize.com/)

And add your redirection conditions based on response of this API.

并根据此API的响应添加重定向条件。

#1


0  

You can try using 3rd party API which responses you the country of visitor.

您可以尝试使用第三方API来回复您访问者的国家/地区。

Try using this API :

尝试使用此API:

http://www.telize.com/geoip/2.20.179.0 (http://www.telize.com/)

And add your redirection conditions based on response of this API.

并根据此API的响应添加重定向条件。