User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 455,985 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,759 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 607 | Replies: 6 | Solved
Reply
Join Date: Aug 2007
Posts: 21
Reputation: rime is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
rime rime is offline Offline
Newbie Poster

IP of a computer

  #1  
Dec 4th, 2007
I am trying to write a code to get IP of a computer.
I have written the following code :
<?php
$ip=@$REMOTE_ADDR;
echo "<font face='Verdana' size='3'><b>IP Address= $ip</b>";
?>
But the output I am getting is :
IP Address= 127.0.0.1
i.e the common IP for all machines, what is the code to get the actual IP of a machine such as 192.163.0.9?
Please help..
Thank you.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: IP of a computer

  #2  
Dec 4th, 2007
$_SERVER['REMOTE_ADDR'] is used to get the IP address of a client.

More about it Here
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Aug 2007
Posts: 21
Reputation: rime is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
rime rime is offline Offline
Newbie Poster

Re: IP of a computer

  #3  
Dec 4th, 2007
Originally Posted by nav33n View Post
$_SERVER['REMOTE_ADDR'] is used to get the IP address of a client.

More about it Here



I have also tried $_SERVER['REMOTE_ADDR'] but it is giving the same output..
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: IP of a computer

  #4  
Dec 4th, 2007
well, thats because, you are probably testing it locally, like, http://localhost/ip.php and most probably, while configuring apache, you have given IP as 127.0.0.1 (or localhost). Try putting it on a server and check. It will work.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: May 2006
Location: ★ ijug.net ★
Posts: 1,012
Reputation: ithelp will become famous soon enough ithelp will become famous soon enough 
Rep Power: 6
Solved Threads: 68
ithelp ithelp is offline Offline
Veteran Poster

Re: IP of a computer

  #5  
Dec 4th, 2007
Are you behind some proxy ?
Reply With Quote  
Join Date: Oct 2007
Posts: 1
Reputation: big.goomba is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
big.goomba big.goomba is offline Offline
Newbie Poster

Solution Re: IP of a computer

  #6  
Dec 4th, 2007
Originally Posted by rime View Post
I am trying to write a code to get IP of a computer.
I have written the following code :
<?php
$ip=@$REMOTE_ADDR;
echo "<font face='Verdana' size='3'><b>IP Address= $ip</b>";
?>
But the output I am getting is :
IP Address= 127.0.0.1
i.e the common IP for all machines, what is the code to get the actual IP of a machine such as 192.163.0.9?
Please help..
Thank you.

Try using one of these: $ip = getenv('REMOTE_ADDR'); --or-- $ip = $REMOTE_ADDR;
Last edited by big.goomba : Dec 4th, 2007 at 11:46 am.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: IP of a computer

  #7  
Dec 4th, 2007
no matter what you use, if you are testing it locally, you will get 127.0.0.1
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 9:28 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC