Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: JC Vásquez
Added: Mar 31, 2021 3:37 PM
Views: 6
Tags: ip
  1. function get_ip() {
  2.     if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
  3.         $ip_address = $_SERVER['HTTP_CLIENT_IP'];
  4.     } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  5.         // IP de un proxy
  6.         $ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
  7.     } else {
  8.         // IP remota
  9.         $ip_address = $_SERVER['REMOTE_ADDR'];
  10.     }
  11.     return $ip_address;
  12. }