Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: user1f787
Added: Sep 4, 2019 8:06 AM
Views: 6
Tags: php
  1. function get_user_ip_address() {
  2.     $client = @$_SERVER['HTTP_CLIENT_IP'];
  3.     $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
  4.     $remote = $_SERVER['REMOTE_ADDR'];
  5.     if (filter_var($client, FILTER_VALIDATE_IP)) {
  6.         $ip = $client;
  7.     } elseif (filter_var($forward, FILTER_VALIDATE_IP)) {
  8.         $ip = $forward;
  9.     } else {
  10.         $ip = $remote;
  11.     }
  12.     return $ip;
  13. }