GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 21-Oct-2003, 17:30
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Question

How to get a User's IP address?


I am working on a really simple stats / logging script for my network of new sites. I am stuck at the moment trying to get the user's IP for my statistics db table and reporting.

There are quite a few possible 'variables' containing this information and this is a list I compiled so far by searching for this info over the last few days:
PHP Code:

<?php
// list of possible variables containing user's IP
$_SERVER['HTTP_X_FORWARDED_FOR'];
$_SERVER['HTTP_X_FORWARDED'];
$_SERVER['HTTP_FORWARDED_FOR'];
$_SERVER['HTTP_FORWARDED'];
$_SERVER['HTTP_X_COMING_FROM'];
$_SERVER['HTTP_COMING_FROM'];
$_SERVER['HTTP_CLIENT_IP'];
$_SERVER['HTTP_VIA'];
$_SERVER['REMOTE_ADDR'];
?>


Do you know of any others for this list? Or how many of those on this list are even still valid?

Besides the variable $_SERVER['REMOTE_ADDR'], which is nearly always set, why and when are the others available to a script?
  #2  
Old 21-Oct-2003, 18:21
BobbyDouglas's Avatar
BobbyDouglas BobbyDouglas is offline
Regular Member
 
Join Date: Aug 2003
Posts: 789
BobbyDouglas has a spectacular aura aboutBobbyDouglas has a spectacular aura about
Nope... But my friend JdS might know.


Doh!
__________________
Mr. Bob's Web Design - Tirelessly looking for ways to enhance the customer base of your business.
  #3  
Old 22-Oct-2003, 04:44
misunderstood misunderstood is offline
Member
 
Join Date: Jun 2003
Posts: 121
misunderstood is on a distinguished road
What about
PHP Code:

$_SERVER["HTTP_REFERER"] 



or have I misunderstood the question? Which wouldnt be unusual
Sorry just read the question again and of course in my rush ignored the IP bit and made a stupid suggestion :0
  #4  
Old 22-Oct-2003, 09:01
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Warning: really off-topic!

Bobby,

Today my horoscope said: Be open to absorbing some new ideas or information today, J. If you keep your eyes and ears open, you might come across something that you have been seeking...... Even a good friend might accidentally mention something pertinent. So put out that radar and soak up interesting waves!

So either you're not a good friend or my radar needs an upgrade!

Misunderstood,

Thank you for trying to help me, I appreciate it even if the information is not what I was hoping for.
  #5  
Old 24-Oct-2003, 10:54
BobbyDouglas's Avatar
BobbyDouglas BobbyDouglas is offline
Regular Member
 
Join Date: Aug 2003
Posts: 789
BobbyDouglas has a spectacular aura aboutBobbyDouglas has a spectacular aura about
why are you trying the others if one of them works all the time?
__________________
Mr. Bob's Web Design - Tirelessly looking for ways to enhance the customer base of your business.
  #6  
Old 24-Oct-2003, 10:58
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
proxy servers
  #7  
Old 24-Oct-2003, 17:01
BobbyDouglas's Avatar
BobbyDouglas BobbyDouglas is offline
Regular Member
 
Join Date: Aug 2003
Posts: 789
BobbyDouglas has a spectacular aura aboutBobbyDouglas has a spectacular aura about
Well the thing is, each of them have some utility in some situation. Setup some if statements to weed them out if they are not set.
__________________
Mr. Bob's Web Design - Tirelessly looking for ways to enhance the customer base of your business.
  #8  
Old 06-Dec-2003, 01:06
cs2 cs2 is offline
Member
 
Join Date: May 2003
Location: California
Posts: 107
cs2 will become famous soon enough
Sorry for the late response, but I just stumbled upon this thread. Anyway... if you are still interested, here is a function I wrote for another project which may help.

PHP Code:

/*
 * Name: Get IP (RFC 1918 compliant)
 * Developer: Bob Wilson (TWI)
 * Creation Date: 5 April, 2003
 * © 2003 by The Whole Internet, LLC
 */

// Access this function (in calling file) by either of the following methods:
// 1. Set variable, eg, $ip=getIP()...then echo, print or test $ip further
// 2. Echo or print function directly...W/O QUOTES (single or double)

function getIP() {
  $octet = explode(".", $_SERVER['HTTP_CLIENT_IP']);
  $refer = explode(".", $_SERVER['REMOTE_ADDR']);
  // check if HTTP_CLIENT_IP same as REMOTE_ADDR
  // if not, reverse array order of entire octet
  if (!empty($refer[0]) && ($refer[0] != $octet[0])) {
    $octet = array_reverse($octet);
  } // endif array compare
  // ternaries to eliminate private addresses, as per rfc1918
  $priv1 = (!empty($octet[0]) && ($octet[0] != 10)) ? 1 : 0;
  $priv2 = ($octet[0] != 172) || ($octet[1] < 16) || ($octet[1] > 31) ? 1 : 0;
  $priv3 = ($octet[0] != 192) || ($octet[1] < 168) ? 1 : 0;
  if ($priv1 && $priv2 && $priv3 != 0) {
    return implode('.',$octet);
  } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    return $_SERVER['HTTP_X_FORWARDED_FOR'];
  } else {
    return $_SERVER['REMOTE_ADDR'];
  } unset($octet, $refer);
} 


__________________
The Whole Internet, LLC
Visit our Homepage, -or-
use our online CSS Editor
  #9  
Old 06-Dec-2003, 09:55
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Thank you for sharing that CS2... unfortunately all my work of the last few months is potentially lost so I have no way to test your little script at the moment.

Once I am able to retrieve my 'lost' files or re-write everything again, I will refer to this thread when I handle the issue.
 
 

Recent GIDBlogNARMY by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
tracking city and country from IP address s786787 Web Design Forum 5 06-Nov-2003 23:23
Rebase - Must Get! BobbyDouglas Miscellaneous Programming Forum 0 18-Aug-2003 04:57
any one knows about the address of the deleted files in FAT shaam CPP / C++ Forum 1 09-Aug-2003 16:18
E-mail address cloaker jrobbio MySQL / PHP Forum 0 16-May-2003 11:23
Slight increase in Netscape users? JdS Web Design Forum 10 01-Sep-2002 11:59

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:34.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.