How to show different homepage based on the user#39;s Country?(如何根据用户所在的国家/地区显示不同的主页?)
问题描述
我有两个域.rajasekar.com 和 rajasekar.in.我需要做的是,
I had two domains. rajasekar.com and rajasekar.in. What I need to do is that,
当来自印度的用户在地址栏中输入网址为 www.rajasekar.com 时,它应该打开 www.rajasekar.in
when a user from India types the url in the address bar as www.rajasekar.com then it should open www.rajasekar.in
当其他国家的用户在地址栏中输入网址为 www.rajasekar.com 时,它应该打开 www.rajasekar.com
When user from other country types the url in the address bar as www.rajasekar.com it should open www.rajasekar.com
我认为这是在 GOOGLE 中实现的.请帮助我实现这一目标
I think this is what implemented in GOOGLE. Please help me in achieving this
推荐答案
你可以尝试根据用户的远程地址猜测国家.
You can try to guess the country based on the remote address of the user.
以下是一个可行的解决方案,但您必须使用重定向逻辑:
The following is a working solution, you'll have to work the redirection logic though:
$remoteAddr = $_SERVER['REMOTE_ADDR'];
$lookupUrl = sprintf('http://api.hostip.info/country.php?ip=%s', $remoteAddr);
$country = trim(file_get_contents($lookupUrl));
if ('IN' === $country)
{
$newUrl = 'http://www.rajasekar.in/';
header(sprintf('Location: %s', $newUrl));
printf('<a href="%s">Moved.</a>', $newUrl);
exit();
}
不过,请注意来自印度的搜索引擎机器人也能够抓取 .com 内容.
Take care that search engine robots from India are able to crawl the .com content as well however.
这篇关于如何根据用户所在的国家/地区显示不同的主页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何根据用户所在的国家/地区显示不同的主页


- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01