Created
December 1, 2015 06:07
-
-
Save onocom/aa248e95ff93d923904e to your computer and use it in GitHub Desktop.
日本からのアクセスと海外からのアクセスの判定をしたかったので作った関数。判定の部分、もっと厳密にしてあげたほうがいいのかしら。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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