Skip to content

Instantly share code, notes, and snippets.

@onocom
Created December 1, 2015 06:07
Show Gist options
  • Save onocom/aa248e95ff93d923904e to your computer and use it in GitHub Desktop.
Save onocom/aa248e95ff93d923904e to your computer and use it in GitHub Desktop.
日本からのアクセスと海外からのアクセスの判定をしたかったので作った関数。判定の部分、もっと厳密にしてあげたほうがいいのかしら。
<?php
/**
* 日本からのアクセスかを判断する
*/
function is_access_from_japan(){
if(!isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) || empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
return false; // よくわからなければ海外からのアクセスとして判定する
}
$lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$pos = strpos($lang, 'ja'); // もうちょいしっかりとチェックしたほうがよいかも?
if( $pos === false ){
return false;
}else{
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment