2023年3月13日发(作者:考试作弊检讨书)
ThtinkPHP的原生函数:
直接套用即可.
function getip() {
$unknown = 'unknown';
if ( ist($_SERVER['HTTP_X_FORWARDED_FOR'])
&& $_SERVER['HTTP_X_FORWARDED_FOR']
&& strcacmp($_SERVER['HTTP_X_FORWARDED_FOR'],
$unknown) ) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} elif ( ist($_SERVER['REMOTE_ADDR'])
&& $_SERVER['REMOTE_ADDR'] &&
strcacmp($_SERVER['REMOTE_ADDR'], $unknown) ) {
$ip = $_SERVER['REMOTE_ADDR'];
}
/*
处理多层代理的情况
或者使用正则方式:$ip = preg_match("/[d.]
{7,15}/", $ip, $matches) ? $matches[0] : $unknown;
*/
if (fal !== strpos($ip,