get visitor IP address or mac address

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

nga
Forum Commoner
Posts: 46
Joined: Mon Aug 17, 2009 3:05 am

get visitor IP address or mac address

Post by nga »

I dont know if this is the right section? Anyway, i've seen websites where users are automatically logout on one computer when they login to the site from another computer.That's pretty handy for website which offers remember me option and still want to secure their users. I know a bit about getting IP address of visitor by using asp .net but with php, i dont know if it possible?
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: get visitor IP address or mac address

Post by susrisha »

yes .. its possible.

Code: Select all

 
$_SERVER[REMOTE_ADDR];//look for the documentation in PHP manual
 
@moderator:
I beleive this post should go to PHP Code forum.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: get visitor IP address or mac address

Post by VladSun »

get visitor IP address or mac address
About getting the user's MAC address - take a look at this:
viewtopic.php?f=6&t=89514
There are 10 types of people in this world, those who understand binary and those who don't
nga
Forum Commoner
Posts: 46
Joined: Mon Aug 17, 2009 3:05 am

Re: get visitor IP address or mac address

Post by nga »

i appreciate it alot you guys :D
nga
Forum Commoner
Posts: 46
Joined: Mon Aug 17, 2009 3:05 am

Re: get visitor IP address or mac address

Post by nga »

this link viewtopic.php?f=6&t=89514 explain how to get mac address in a LAN or wireless network. i want to get visitor(of my website)'s MAC address. Is is possible by php or something else?
nga
Forum Commoner
Posts: 46
Joined: Mon Aug 17, 2009 3:05 am

Re: get visitor IP address or mac address

Post by nga »

oh i get it, do you mean we cant get MAC address?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: get visitor IP address or mac address

Post by VladSun »

Simply, you can get the user's MAC address in a single network segment (like "Intranet" sites) but you can't get it in the Internet network.
There are 10 types of people in this world, those who understand binary and those who don't
nga
Forum Commoner
Posts: 46
Joined: Mon Aug 17, 2009 3:05 am

Re: get visitor IP address or mac address

Post by nga »

For example, if you login to a website(donot logout) and then using another computer(same LAN and same public IP address) login to that website then the website cannot identify that you have log in from abother computer?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: get visitor IP address or mac address

Post by VladSun »

(same LAN and same public IP address)
I supose you mean that the LAN IPs are routed to Internet by using SNAT (PAT) - i.e. single public IP.

In this case you can distinguish them by using the session ID or some cookie information.
There are 10 types of people in this world, those who understand binary and those who don't
nga
Forum Commoner
Posts: 46
Joined: Mon Aug 17, 2009 3:05 am

Re: get visitor IP address or mac address

Post by nga »

do session IDs not disappear when you close the browser? Well, i gues what i want to ask is to mimic this website neopets.com (when you login to the site from a different computer, the next time you/someone else visit the website on the old computer, your account are logged out even though the computer you used is still in the same LAN). I figured that they use MAC address or something? or they use a combination of cookies and IP address?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: get visitor IP address or mac address

Post by pickle »

I don't think IP addresses need to be stored at all.

When a user logs in on computer A, that computer gets a cookie with a session ID. That same session ID is stored server-side and is associated with that particular user.

When that same user accesses the site via computer B, computer B doesn't have a cookie with the proper session ID, so the user isn't logged in. If the user logs in on computer B, computer B gets a session ID, and the server is updated with the session ID as stored on computer B.

At this point, computer A no longer has the proper session ID for the user, so it is treated as a non-logged in user.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
nga
Forum Commoner
Posts: 46
Joined: Mon Aug 17, 2009 3:05 am

Re: get visitor IP address or mac address

Post by nga »

then the user account is still vulnerable if the cookie is captured? So in order to be really really secure, sessionID, IPaddress should be used together? if session ID the same and IP address is different +> cookie might be capture => logout. Seem like a great idea
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: get visitor IP address or mac address

Post by jackpf »

That's how most people do it I believe. Some people also check user agents to make sure the browser is the same.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: get visitor IP address or mac address

Post by VladSun »

Another related thread to point to:
viewtopic.php?f=19&t=96910
:)
There are 10 types of people in this world, those who understand binary and those who don't
nga
Forum Commoner
Posts: 46
Joined: Mon Aug 17, 2009 3:05 am

Re: get visitor IP address or mac address

Post by nga »

about IP spoofing, I'm curious on how this could be done and how to prevent it?
Post Reply