Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Amit Sarker
Added: Jan 23, 2018 7:54 AM
Modified: Jan 28, 2018 5:35 AM
Views: 27
Tags: no tags
  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. }