473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

getting the client IP address

omerbutt
638 512MB
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

✓ answered by dlite922

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

5 3008
prabirchoudhury
162 100+
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 Expert 1GB
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 512MB
@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 Expert 1GB
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 512MB
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
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...
3
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...
4
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 =...
4
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...
4
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...
14
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
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
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...
1
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...
29
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() { //...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.