获取ip地址
function getUserRealIP() { $headers = array( 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR' ); foreach ($headers as $header) { if (isset($_SERVER[$header]) && filter_var($_SERVER[$header], FILTER_VALIDATE_IP)) { return $_SERVER[$header]; } } return $_SERVER['REMOTE_ADDR']; } $userIP = getUserRealIP(); echo $userIP;