How do you detect a website visitor's country (Specifically, US or not)?

前端 未结 8 2017
無奈伤痛
無奈伤痛 2020-12-12 19:11

I need to show different links for US and non-US visitors to my site. This is for convenience only, so I am not looking for a super-high degree of accuracy, and security or

8条回答
  •  感情败类
    2020-12-12 20:07

    My solution, easy and small, in this example i test Canada region from language fr-CA or en-CA

    if( preg_match( "/^[a-z]{2}\-(ca)/i", $_SERVER[ "HTTP_ACCEPT_LANGUAGE" ] ) ){
    
       $region = "Canada";
    
    }
    

提交回复
热议问题