HTML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignHTML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 3rd, 2003, 10:44 AM
paulsiew2 paulsiew2 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 15 paulsiew2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
How To Retrieve Client Ip Address

Hi,

Anyone know how to retrieve Client's IP Address, my php webserver was behind the proxy (firewall)?
When i use --> $REMOTE_ADDR , show my proxy's IP address..
$HTTP_X_FORWARDED_FOR , show nothing

Javascript below only works for Netscape, return nothing in IE,

<script language="JavaScript"><!--
if (navigator.appName=='Netscape' && navigator.javaEnabled()) {
hn = java.net.InetAddress.getLocalHost().getHostName();
ha = java.net.InetAddress.getLocalHost().getHostAddress();
document.write('HostName: '+ hn + '<br>' + 'HostAddress: '+ ha );
}
//--></script>


Thanks in Advance!


PauL

Reply With Quote
  #2  
Old June 3rd, 2003, 11:15 AM
Sepodati's Avatar
Sepodati Sepodati is offline
Banned
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Dec 1999
Location: Afghanistan
Posts: 14,401 Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)  Folding Points: 79571 Folding Title: Intermediate FolderFolding Points: 79571 Folding Title: Intermediate FolderFolding Points: 79571 Folding Title: Intermediate FolderFolding Points: 79571 Folding Title: Intermediate Folder
Time spent in forums: 2 Months 4 Weeks 1 Day 14 h 33 m 56 sec
Reputation Power: 2089
Send a message via ICQ to Sepodati Send a message via Yahoo to Sepodati
You cannot depend upon any method to get the IP address. Some proxies just will not send it at all.

Shouldn't this be in the PHP or Javascript forum? What kind of solution (client or server side) do you want?

---John Holmes...

Reply With Quote
  #3  
Old June 4th, 2003, 09:04 PM
paulsiew2 paulsiew2 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 15 paulsiew2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Sorry..Wrong forum!
As stated above, i need to get client's ip address, any method...pls

Reply With Quote
  #4  
Old June 4th, 2003, 09:43 PM
Chameleon Chameleon is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Posts: 90 Chameleon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 17 m 48 sec
Reputation Power: 0
Send a message via AIM to Chameleon
Well there isn't a 100% reliable way to do it due to proxy servers, etc...

Reply With Quote
  #5  
Old June 4th, 2003, 09:53 PM
Sepodati's Avatar
Sepodati Sepodati is offline
Banned
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Dec 1999
Location: Afghanistan
Posts: 14,401 Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)  Folding Points: 79571 Folding Title: Intermediate FolderFolding Points: 79571 Folding Title: Intermediate FolderFolding Points: 79571 Folding Title: Intermediate FolderFolding Points: 79571 Folding Title: Intermediate Folder
Time spent in forums: 2 Months 4 Weeks 1 Day 14 h 33 m 56 sec
Reputation Power: 2089
Send a message via ICQ to Sepodati Send a message via Yahoo to Sepodati
Why do you think you need to get the IP address?

Reply With Quote
  #6  
Old June 5th, 2003, 12:45 PM
sizeof sizeof is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 31 sizeof User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Hi,

Usually proxies send the real client IP via a HTTP proxy header (usually HTTP_CLIENT_IP or HTTP_X_FORWARDED_FOR).

So you should always attempt to extract the real client IP and use it instead of the proxy IP. Remember - sometimes it's impossible (anonymous proxies) - and no matter what you do - you'll always get the IP of the proxy.

Try using this function to get the client IP, instead of REMOTE_ADDR or anything similar.

PHP Code:
<?
function get_client_ip ()
{
    
// Get REMOTE_ADDR as the Client IP.
    
$client_ip = ( !empty($_SERVER['REMOTE_ADDR']) ) ? $_SERVER['REMOTE_ADDR'] : ( ( !empty($_ENV['REMOTE_ADDR']) ) ? $_ENV['REMOTE_ADDR'] : $REMOTE_ADDR );

    
// Check for headers used by proxy servers to send the Client IP. We should look for HTTP_CLIENT_IP before HTTP_X_FORWARDED_FOR.
    
if ($_SERVER["HTTP_CLIENT_IP"])
        
$proxy_ip $_SERVER["HTTP_CLIENT_IP"];
    elseif (
$_SERVER["HTTP_X_FORWARDED_FOR"])
        
$proxy_ip $_SERVER["HTTP_X_FORWARDED_FOR"];

    
// Proxy is used, see if the specified Client IP is valid. Sometimes it's 10.x.x.x or 127.x.x.x... Just making sure.
    
if ($proxy_ip)
    {
        if ( 
preg_match("/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/"$proxy_ip$ip_list) )
        {
            
$private_ip = array('/^0\./''/^127\.0\.0\.1/''/^192\.168\..*/''/^172\.16\..*/''/^10.\.*/''/^224.\.*/''/^240.\.*/');
            
$client_ip preg_replace($private_ip$client_ip$ip_list[1]);
        }
    }

    
// Return the Client IP.
    
return $client_ip;
}
?>


Aviv Shaham
Think Offshore, Inc.
http://www.think-offshore.com

Reply With Quote
  #7  
Old June 5th, 2003, 12:57 PM
ngahleng ngahleng is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Location: singapore
Posts: 16 ngahleng User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
try echo phpinfo(); see what u can get.

Reply With Quote
  #8  
Old June 5th, 2003, 09:36 PM
paulsiew2 paulsiew2 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 15 paulsiew2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy

it still showing the proxy ip address

Reply With Quote
  #9  
Old June 5th, 2003, 09:50 PM
a.koepke's Avatar
a.koepke a.koepke is offline
Second highest poster :p
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Jul 2001
Posts: 7,323 a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 8 h 13 m 55 sec
Reputation Power: 27
Listen to Sepo

Quote:
You cannot depend upon any method to get the IP address. Some proxies just will not send it at all.

Reply With Quote
  #10  
Old June 5th, 2003, 09:59 PM
Sepodati's Avatar
Sepodati Sepodati is offline
Banned
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Dec 1999
Location: Afghanistan
Posts: 14,401 Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)  Folding Points: 79571 Folding Title: Intermediate FolderFolding Points: 79571 Folding Title: Intermediate FolderFolding Points: 79571 Folding Title: Intermediate FolderFolding Points: 79571 Folding Title: Intermediate Folder
Time spent in forums: 2 Months 4 Weeks 1 Day 14 h 33 m 56 sec
Reputation Power: 2089
Send a message via ICQ to Sepodati Send a message via Yahoo to Sepodati
Is there an echo in here?

---John Holmes...

Reply With Quote
  #11  
Old June 5th, 2003, 10:12 PM
paulsiew2 paulsiew2 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 15 paulsiew2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by SepodatiCreations
You cannot depend upon any method to get the IP address. Some proxies just will not send it at all.

Shouldn't this be in the PHP or Javascript forum? What kind of solution (client or server side) do you want?

---John Holmes...



yup..it might not work at server site, that's y i'm looking for client site scripts like Javascript or VBScript, those script post the ip back as a parameter to my php..but no luck

Reply With Quote
  #12  
Old June 5th, 2003, 10:26 PM
Sepodati's Avatar
Sepodati Sepodati is offline
Banned
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Dec 1999
Location: Afghanistan
Posts: 14,401 Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)Sepodati User rank is General 16th Grade (Above 100000 Reputation Level)  Folding Points: 79571 Folding Title: Intermediate FolderFolding Points: 79571 Folding Title: Intermediate FolderFolding Points: 79571 Folding Title: Intermediate FolderFolding Points: 79571 Folding Title: Intermediate Folder
Time spent in forums: 2 Months 4 Weeks 1 Day 14 h 33 m 56 sec
Reputation Power: 2089
Send a message via ICQ to Sepodati Send a message via Yahoo to Sepodati

Reply With Quote
  #13  
Old June 5th, 2003, 10:46 PM
paulsiew2 paulsiew2 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 15 paulsiew2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
tried the script..not working..

Reply With Quote
<