Get users' IP Address with PHP


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function getRealIpAddr()
  2. {
  3. if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
  4. {
  5. $ip=$_SERVER['HTTP_CLIENT_IP'];
  6. }
  7. elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
  8. {
  9. $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
  10. }
  11. else
  12. {
  13. $ip=$_SERVER['REMOTE_ADDR'];
  14. }
  15. return $ip;
  16. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.