need to include one file or another based on visitor country

假如想象 提交于 2019-12-11 15:46:05

问题


Visitors from either of 3 countries - New Zealand, Fiji or India - need a different content page respectively. The site is written in PHP, the content is in HTML files ready to be included.... I'm a newb; please be patient!!


回答1:


It's pretty easy to use Google's AJAX API loader to get a rough estimate of the user's location. Roughly:

<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript">

// Note that you should have some sanity checks here, and maybe use an onLoad
// event of some kind
alert(google.loader.ClientLocation.address.country);

</script>

You could have the user start at a page that would then use JavaScript to redirect them to the appropriate location. If you're using any popular JavaScript libraries, you may already be using this loader (and if not, you should consider loading your libraries through it).

http://code.google.com/apis/ajax/documentation/#ClientLocation




回答2:


  • Get the visitor's IP
  • Map the IP to its location
  • Do a conditional include based on the location


来源:https://stackoverflow.com/questions/2687801/need-to-include-one-file-or-another-based-on-visitor-country

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!