Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am hosting a website and i require to know IP address of users of my website. How can i do that in PHP language.

Also IP address of users changes dynamically , so can we know their NIC No. or something similar to it which can identify them uniquely?
Posted
Updated 27-Jun-12 22:43pm
v2

IP Address:
(from http://admincmd.blogspot.com/2007/08/php-get-client-ip-address.html[^])

PHP
function getIP() { 
    $ip; 
    if (getenv("HTTP_CLIENT_IP")) 
        $ip = getenv("HTTP_CLIENT_IP"); 
    else if(getenv("HTTP_X_FORWARDED_FOR")) 
        $ip = getenv("HTTP_X_FORWARDED_FOR"); 
    else if(getenv("REMOTE_ADDR")) 
        $ip = getenv("REMOTE_ADDR"); 
    else 
        $ip = "0.0.0.0";
    return $ip; 
} 


What is NIC no? Are you referring to MAC address?

MAC: I don't think you can get this. As far as I know, MAC addresses are dealt by lower layers of the communication stack. So theoretically your code will not be exposed to that low level of information.

However, if your client is in the same LAN as your server, there's a workaround. See the similar question in StackOverflow: http://stackoverflow.com/questions/1420381/how-can-i-get-the-mac-and-the-ip-address-of-a-connected-client-in-php[^]
 
Share this answer
 
Comments
[no name] 28-Jun-12 5:26am    
Thanks a lot. I will try this and let you know.

By default IP changes dynamically everytime you connect to the internet. And i want to know a user distinctly. So how is it possible? Can You Suggest anything related to it?
[no name] 28-Jun-12 6:28am    
Yes its working, but still i need to know a method in which i want to identify a pc uniquely forever.
echo sprintf('Local IP address: %s', gethostbyname($_SERVER_NAME));


above code will be result user's local machine's ip

above code is run in offline ok but.....
If this not work on your server plz send support ticket for this..
I hope it will help you..
thanks
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900