Get ip from visiting pc/user

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Axllrod
Forum Newbie
Posts: 12
Joined: Tue Jun 12, 2012 4:15 pm
Location: Belgium

Get ip from visiting pc/user

Post by Axllrod »

I have been looking for a way to get the ip from the visiting pc on a website. I would need the ip to check if a visitor has already submitted a form from the website. So when this pc visits the website, it doesn't show the form.
I have found this bit of code here to do so:

Code: Select all

$_SERVER['REMOTE_ADDR']
This bit of code does work and it does give an ip but it seems it's not from a pc or device.
If i try to connect with another pc on the same network (such as wifi), then it's the same ip on all the devices. So it seems it takes the ip from the router and not from the pc itself.

Thanks in advance!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Get ip from visiting pc/user

Post by Christopher »

Axllrod wrote:So it seems it takes the ip from the router and not from the pc itself.
That's what a router does -- route traffic between two separate IP networks. In order to get information about the computer itself you would need to install an application on that pc that has access to the OS. Could be a browser plugin or a Java app or us one of Microsoft's several methods..
(#10850)
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Get ip from visiting pc/user

Post by social_experiment »

Also take into account that users can visit the site through sites like anonymouse, when connecting via a proxy or non-static ip address; all these will bypass the measure you have in place
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply