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, 09: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, 10:15 AM
Sepodati's Avatar
Sepodati Sepodati is offline
Banned
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Dec 1999
Location: Kentucky
Posts: 14,429 Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)  Folding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced Folder
Time spent in forums: 3 Months 1 Day 17 h 28 m 7 sec
Reputation Power: 2546
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, 08: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, 08: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, 08:53 PM
Sepodati's Avatar
Sepodati Sepodati is offline
Banned
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Dec 1999
Location: Kentucky
Posts: 14,429 Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)  Folding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced Folder
Time spent in forums: 3 Months 1 Day 17 h 28 m 7 sec
Reputation Power: 2546
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, 11:45 AM
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: 7
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, 11:57 AM
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, 08: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, 08: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, 08:59 PM
Sepodati's Avatar
Sepodati Sepodati is offline
Banned
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Dec 1999
Location: Kentucky
Posts: 14,429 Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)  Folding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced Folder
Time spent in forums: 3 Months 1 Day 17 h 28 m 7 sec
Reputation Power: 2546
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, 09: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, 09:26 PM
Sepodati's Avatar
Sepodati Sepodati is offline
Banned
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Dec 1999
Location: Kentucky
Posts: 14,429 Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)  Folding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced Folder
Time spent in forums: 3 Months 1 Day 17 h 28 m 7 sec
Reputation Power: 2546
Send a message via ICQ to Sepodati Send a message via Yahoo to Sepodati

Reply With Quote
  #13  
Old June 5th, 2003, 09: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
  #14  
Old June 5th, 2003, 09:49 PM
Sepodati's Avatar
Sepodati Sepodati is offline
Banned
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Dec 1999
Location: Kentucky
Posts: 14,429 Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)Sepodati User rank is General 23rd Grade (Above 100000 Reputation Level)  Folding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced Folder
Time spent in forums: 3 Months 1 Day 17 h 28 m 7 sec
Reputation Power: 2546
Send a message via ICQ to Sepodati Send a message via Yahoo to Sepodati
"not working" means what?

Reply With Quote
  #15  
Old June 5th, 2003, 09:54 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
not showing the ip at all...this what i get,

"Your IP address is <!--#echo var=\"REMOTE_ADDR\"-->"


oringinal script:

<?
echo"
<head>
<SCRIPT LANGUAGE=\"JavaScript\">

<!-- Begin

// This part gets the IP
var ip = '<!--#echo var=\"REMOTE_ADDR\"-->';

// This part is for an alert box
alert(\"Your IP address is \"+ip);

// This part is for the status bar
window.defaultStatus = \"Your IP address is \"+ip;

// This part is for the title bar
document.write(\"<title>Your IP address is \"+ip+\"</title>\");
// End -->
</script>
</head>";
?>

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignHTML Programming > How To Retrieve Client Ip Address


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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 On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT