473,545 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Identifying IP address

I know that identifying the user IP address with

HTTP_SERVER_VAR S['REMOTE_ADDR'];

is reliant on the browser agent but I have stumpled upon the following
code which I have tried to understand but failed!

//
// Obtain and encode users IP
//

function encode_ip($dotq uad_ip)
{
$ip_sep = explode('.', $dotquad_ip);
return sprintf('%02x%0 2x%02x%02x', $ip_sep[0], $ip_sep[1],
$ip_sep[2], $ip_sep[3]);
}

if( getenv('HTTP_X_ FORWARDED_FOR') != '' )
{
$client_ip = ( !empty($HTTP_SE RVER_VARS['REMOTE_ADDR']) ) ?
$HTTP_SERVER_VA RS['REMOTE_ADDR'] : ( (
!empty($HTTP_EN V_VARS['REMOTE_ADDR']) ) ?
$HTTP_ENV_VARS['REMOTE_ADDR'] : $REMOTE_ADDR );

$entries = explode(',', getenv('HTTP_X_ FORWARDED_FOR') );
reset($entries) ;
while (list(, $entry) = each($entries))
{
$entry = trim($entry);
if ( preg_match("/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/", $entry,
$ip_list) )
{
$private_ip = array('/^0\./', '/^127\.0\.0\.1/',
'/^192\.168\..*/', '/^172\.((1[6-9])|(2[0-9])|(3[0-1]))\..*/',
'/^10\..*/', '/^224\..*/', '/^240\..*/');
$found_ip = preg_replace($p rivate_ip, $client_ip,
$ip_list[1]);

if ($client_ip != $found_ip)
{
$client_ip = $found_ip;
break;
}
}
}
}
else
{
$client_ip = ( !empty($HTTP_SE RVER_VARS['REMOTE_ADDR']) ) ?
$HTTP_SERVER_VA RS['REMOTE_ADDR'] : ( (
!empty($HTTP_EN V_VARS['REMOTE_ADDR']) ) ?
$HTTP_ENV_VARS['REMOTE_ADDR'] : $REMOTE_ADDR );
}
$user_ip = encode_ip($clie nt_ip);
It outputs the IP address in something that resembles a hex number? Is
it a more reliable way of identifying an IP?
Jul 17 '05 #1
1 6136
"David" <bi****@hotmail .com> wrote in message
news:3e******** *************** ***@posting.goo gle.com...
I know that identifying the user IP address with

HTTP_SERVER_VAR S['REMOTE_ADDR'];

is reliant on the browser agent but I have stumpled upon the following
code which I have tried to understand but failed!

.........

It outputs the IP address in something that resembles a hex number? Is
it a more reliable way of identifying an IP?

No, it uses the same aproach, it looks like it is showing you the hex or log
value of the ip
(i didnt read all the way through it)

You should user $_SERVER['REMOTE_ADDR'];

also, I have never know the IP address to be dependent on the browser (you
may be thinking of user agent or referer)

if someone connects to a web server, the web server *MUST* know the IP
address so it can send the page back to the browser.

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1474
by: angel duran | last post by:
i already know how to load the my list of suppliers using mysql/php/apache, but what i would like to do now is put a link for each and every supplier and when someone clicks it, they will automatically go to that supplier's list of products. i want something like this: SUPPLIERS TABLE supplierID, Name, Address,
3
3753
by: Roger Withnell | last post by:
I have several web sites running the same set of pages and all accessing the same common database tables. A field in all the records contains the web site address of the web site to which each record pertains, for example, this field in some records may contain www.upperbridge.co.uk. When a web site page accesses a database table, it needs...
1
1709
by: Hafez | last post by:
Hi All The problem:!! I want to create a temp table which is common between different users so that each user could select his rows and print them without printing others selection. All clients use the same connection string. Is there a way to identify users? I think it's possible to delete rows of a user when he logs out the program. Do...
1
1225
by: Ted Geranium via AccessMonster.com | last post by:
Hi I wonder if anyone can help.. I run a query and report all records to a list box.. I have created the following to copy a single record into a second list box as follows: Dim SQLstmt As String SQLstmt = SQLstmt & "INSERT INTO Temp (ID, Salutation, , Street, Locality, , Town, County, Postcode) " SQLstmt = SQLstmt & "SELECT...
6
4029
by: Atley | last post by:
I have a Terminal Services server running Windows 2000 Server. I need to be able to identify, in my application on that server, which client computer is addressing that server and running that application. it can be by IP or by machine network name... Doesn't matter. I am using Visual Basic .Net 2003 Any help would be greatly...
4
1840
by: PaulF | last post by:
How do I identify all of the namespace / prefix pairs associated with an XML document I am reading? Thanks for any help. Paul
1
2812
by: jalgoza | last post by:
The address field in my User table has data like: 1905 1905 S OAK ST 314 ROSSELL AVE 252 252 HIGH MEADOWS ST 1402 1402 TOWNSEND CT 2021 MAHAN AVE 347 347 N 7 AVE As you see we have repeating House #s here. I would like to write a query to:
10
4485
by: Frankie | last post by:
It appears that System.Random would provide an acceptable means through which to generate a unique value used to identify multiple/concurrent asynchronous tasks. The usage of the value under consideration here is that it is supplied to the AsyncOperationManager.CreateOperation(userSuppliedState) method... with userSuppliedState being, more...
11
1138
by: D'Arcy J.M. Cain | last post by:
On Wed, 5 Mar 2008 13:38:59 -0800 (PST) Mike Driscoll <kyosohma@gmail.comwrote: I'm not sure why you change the address like this but could you please include the full address. Those of us who identify the time wasters would also like to drop the responses to their posts and changing the address makes this impossible. -- D'Arcy J.M....
0
7425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7935
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7449
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7780
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5069
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3479
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3465
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1911
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1037
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.