IP source avec PHP

Soumis par Nothing2Do.fr le mer 12/01/2022 - 10:48

how to get IP adress in php :

  1. <?php  
  2.     function getIPAddress() {  
  3.     //whether ip is from the share internet  
  4.      if(!emptyempty($_SERVER['HTTP_CLIENT_IP'])) {  
  5.                 $ip = $_SERVER['HTTP_CLIENT_IP'];  
  6.         }  
  7.     //whether ip is from the proxy  
  8.     elseif (!emptyempty($_SERVER['HTTP_X_FORWARDED_FOR'])) {  
  9.                 $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];  
  10.      }  
  11. //whether ip is from the remote address  
  12.     else{  
  13.              $ip = $_SERVER['REMOTE_ADDR'];  
  14.      }  
  15.      return $ip;  
  16. }  
  17. $ip = getIPAddress();  
  18. echo 'User Real IP Address - '.$ip;  
  19. ?>