Posted By

DrewDouglass on 07/12/09


Tagged

php


Versions (?)

Who likes this?

6 people have marked this snippet as a favorite

vali29
irishsk
GandalfGrey
tigerthemes
qubestream
alberfp


Get Real IP Address with PHP


 / Published in: PHP
 

URL: http://roshanbh.com.np/2007/12/getting-real-ip-address-in-php.html

All credit for this snippet goes to Roshan, link is given above.

  1. <?php
  2. function getRealIpAddr(){
  3. if (!empty($_SERVER['HTTP_CLIENT_IP'])){
  4. //check ip from share internet
  5. $ip = $_SERVER['HTTP_CLIENT_IP'];
  6. }
  7. elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
  8. //to check ip is pass from proxy
  9. $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  10. }
  11. else{
  12. $ip = $_SERVER['REMOTE_ADDR'];
  13. }
  14. return $ip;
  15. }
  16. ?>

Report this snippet  

You need to login to post a comment.