Showing posts with label grab ip. Show all posts
Showing posts with label grab ip. Show all posts

Friday, July 20, 2012

Find visitor's IP address in php script

Every php developer want to store IP address of visitor for tracking and other different purpose. Here is the function which i'm using in my script to store ip address in database.

<?php
/* 
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/
function visitorIPAdd()
{
/*
This returns the IP of the visitor calling the requested page
Checks to see if HTTP_X_FORWARDED_FOR has a value then the client is operating via a proxy
*/
       $visitorIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
       if($visitorIP == "")
      { 
         $visitorIP = $_SERVER['REMOTE_ADDR'];  
      }

      return $visitorIP;       // return the IP address
}
?>

 

© 2014 4everTutorials. All rights resevered.

Back To Top