473,765 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting the client IP address

omerbutt
638 Contributor
can any body tell me the right code to get the client ip address,i have tried these two ways
Expand|Select|Wrap|Line Numbers
  1.     //$ip=@$REMOTE_ADDR;
  2.     $ip=$_SERVER['REMOTE_ADDR']; 
  3.  
but it gives me 127.0.0.1 where as i want such figure 203933791.
i am using the ip database

regards
Omer Aslam
May 16 '09 #1
5 3023
prabirchoudhury
162 New Member
previous version of php could support $REMORT_ADDR but not the > PHP4.

here you go for the right

Expand|Select|Wrap|Line Numbers
  1.  
  2. $ip =getenv("REMOTE_ADDR");
  3.  
  4.  
  5.  
that would give you the client IP address
May 17 '09 #2
dlite922
1,584 Recognized Expert Top Contributor
Your question is not related to PHP but needs some basic networking knowledge to explain what is happening. 127.0.0.1 is the default (standard) IP for the local loopback. You're webserver sees the request coming from your computer and assigns this IP address to it.

If you're friend accessed it from outside network you'd probably get his IP address (or his firewall's).

So in short, the code is working and that is technically your IP address if you're accessing the page from the web server itself (where PHP is installed).

Cheers,



Dan



@omerbutt
May 18 '09 #3
omerbutt
638 Contributor
@prabirchoudhury
ok let me check it out if it works for me or not ,still thanks for looking @
regards
Omer Aslam
May 19 '09 #4
hsriat
1,654 Recognized Expert Top Contributor
Has nothing to do with $_SERVER['REMOTE_ADDR'] or getenv. Both will give you same value. If you upload your page on a server, it will work properly.

Dan tried to explain you the relevant theory, but I think you were not interested. So just believe in this that $_SERVER['REMOTE_ADDR'] will work for you, but when script is on your server and not local machine.

For details, check out this page: http://php.net/getenv
May 20 '09 #5
omerbutt
638 Contributor
thanks alot man it just worked
regards,
Omer aslam
May 22 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
2298
by: Chris | last post by:
<apologies for cross-posting> Hi All, I am based in the UK and have been doing some private work for a client which involved setting up a database and scripts to search it and display results etc, all the usual stuff. The work was at about the halfway point when the client asked for a time estimate for the whole project. I sent him this and he wrote back
3
8983
by: roger beniot | last post by:
I would like to figure out how to detect an IP address change for an XP/Win2K3 machine that is leasing an IP via DHCP (and do it in C#)... Is there any event that indicates an IP address change?... I really don't want to poll for a change. I would like to get an event indicating the IP address has changed and propogate that change to other levels of my app. If anyone has a solution that isn't in C# I am interested in that as
4
4572
by: anonymous_c | last post by:
Hey guys. I'm creating a file transfer app. Anyways, I'm using this code... SERVER <code>Dim Hostname As String = Dns.GetHostName Dim IP As String = Dns.GetHostByName(Hostname).AddressList(0).ToString Public Sub RunServer() Dim listener As TcpListener
4
4771
by: Andy | last post by:
Hi all, I'm trying to write some code in a business layer which will audit the IP address that the request is coming from. If the business layer is being called from a web app, I'd like to get the IP address of the client browser, but if the business layer is being called from a desktop app, i'd like to capture the desktop's IP address.
4
6097
by: Goh | last post by:
Hi, I would like to know how can we implement a web page that intelligent enough to unique identify that pc have been visit before without any cookies and login user require. I have try implement this by MAC address. When user browser the web site I sometime can get user pc MAC and sometime no. Why this type of implementation are so not consistency? Does any
14
4450
by: Ankit Aneja | last post by:
The code of classes given below is for server to which clients connect i want to get ip address of client which has connected pls help how can i get //listen class public class listen {
6
10751
by: Prabhat | last post by:
Hi Friends, It it possible to get the MAC Address of the client PC using ASP. Also can I get the HDD ID/Serial Number also using asp? Please advice. Thanks Prabhat
4
7313
by: Macca | last post by:
Hi, I am using an asynchronous socket server to allow comms between multiple clients and my server. I know how to obtain the IPAddress of the client (network device) as shown below :- string sensorIPAddress = ((IPEndPoint)handler.RemoteEndPoint).Address.ToString(); but what I would like to obtain is the physical/MACID of the client.
1
3199
by: simbarashe | last post by:
Hie could someone please help me with getting and using the current page url. I have a function that gets the url, I want to use it with header(location : XXX) but it wont work. The code is as follows: The code below is for the first page:session_start is in line 3 <link href="css/jobSheet.css" rel="stylesheet" type="text/css" /> session_start();
29
37505
pradeepjain
by: pradeepjain | last post by:
Hii, I need to know is there any way to get the mac id's of the machines accessing ma site! I want to make a access lock using the mac id's <?php function returnmacaddress() { // This code is under the GNU Public Licence // Written by michael_stankiewicz {don't spam} at yahoo {no spam} dot com // Tested only on linux, please report bugs // WARNING: the commands 'which' and 'arp' should be executable
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9399
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9957
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9835
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
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.