Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
AYK
Hangin' Around



Joined: Apr 03, 2004
Posts: 32

PostPosted: Sun Apr 18, 2004 1:51 pm Reply with quote

Hello, I've been looking around but I can't seem to find a function for PHP dat registers the visitors IP.

I'm making a counter based on the fact that the viewing of index.php adds a row to my counter table where the date+time of the visit is stored too.
The counter value is MYSQL_NUM_ROWS. But I would like to add the vistitors IP adress also. Any ideas ?
 
View user's profile Send private message Visit poster's website
AYK







PostPosted: Sun Apr 18, 2004 2:56 pm Reply with quote

DEVSHED forum provided my answer :

Code:
 $_SERVER['remote_addr'] 
 
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Sun Apr 18, 2004 3:22 pm Reply with quote

That will not work all the time especially with proxies and such. Try this instead Wink
Code:
if (isSet($_SERVER)) {

      if (isSet($_SERVER["HTTP_X_FORWARDED_FOR"])) {
         $realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
      } elseif (isSet($_SERVER["HTTP_CLIENT_IP"])) {
         $realip = $_SERVER["HTTP_CLIENT_IP"];
      } else {
         $realip = $_SERVER["REMOTE_ADDR"];
      }

} else

   if (isSet($HTTP_SERVER_VARS)) {
      if (isSet($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"])) {
         $realip = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"];
      } elseif (isSet($HTTP_SERVER_VARS["HTTP_CLIENT_IP"])) {
         $realip = $HTTP_SERVER_VARS["HTTP_CLIENT_IP"];
      } else {
         $realip = $HTTP_SERVER_VARS["REMOTE_ADDR"];
      }

} else {
      if ( getenv( 'HTTP_X_FORWARDED_FOR' ) ) {
         $realip = getenv( 'HTTP_X_FORWARDED_FOR' );
      } elseif ( getenv( 'HTTP_CLIENT_IP' ) ) {
         $realip = getenv( 'HTTP_CLIENT_IP' );
      } else {
         $realip = getenv( 'REMOTE_ADDR' );
      }
}
 
View user's profile Send private message
AYK







PostPosted: Sun Apr 18, 2004 3:56 pm Reply with quote

Thanks ! fantastic ! Very Happy Very Happy
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©