udaystrad Posted December 6, 2013 Share Posted December 6, 2013 Hey i have tried many codes..... this is one example of it..... The scenario is as folows... I have an IP hosted on a server... I want to kno who accesses the files of that IP... the codes that i tried yet, give out the IP of my own server or nothin at all... <?php $ip = $_SERVER['REMOTE_ADDR']; if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } Echo "Client IP is " . $ip; ?> Quote Link to comment https://forums.phpfreaks.com/topic/284574-how-to-get-client-ip/ Share on other sites More sharing options...
requinix Posted December 6, 2013 Share Posted December 6, 2013 So you have some sort of setup involving load balancing or proxies? How and from where are you accessing the server? Quote Link to comment https://forums.phpfreaks.com/topic/284574-how-to-get-client-ip/#findComment-1461458 Share on other sites More sharing options...
udaystrad Posted December 6, 2013 Author Share Posted December 6, 2013 the server is at my office.... i have tried acessing from diff locations ie from my house, frnds house. But the above code is giving the location of itself as may be the code itself generates its own location. All done from a computer. If i have understood your first question this is the answer for it. There isnt any load on the server and it does not involve proxies. Its an app were the staff would login-logout for attendance. I dont want them to access from anyother loaction other than my office. So code should be as such that only accessing the pages from the office would mark them present. In order for me to do that i need to kno the location of the staff using my attendance app. Quote Link to comment https://forums.phpfreaks.com/topic/284574-how-to-get-client-ip/#findComment-1461466 Share on other sites More sharing options...
kicken Posted December 6, 2013 Share Posted December 6, 2013 If the app is something which should only be accessible from within the office, then you could just setup your server to only listen to LAN addresses and not any public addresses. Then the app would only load for someone who is on the local LAN at the office. If you are not getting the IP you expect from the code above, then you are accessing the server indirectly in someway, either via a proxy, ssh tunnel, vpn, etc. Depending on what is inbetween, you may or may not be able to get the original IP address. Quote Link to comment https://forums.phpfreaks.com/topic/284574-how-to-get-client-ip/#findComment-1461488 Share on other sites More sharing options...
udaystrad Posted December 7, 2013 Author Share Posted December 7, 2013 (edited) The server is a VPS server so cannot setup to only to LAN addresses. Will get back to you regarding the second solution. Edited December 7, 2013 by udaystrad Quote Link to comment https://forums.phpfreaks.com/topic/284574-how-to-get-client-ip/#findComment-1461556 Share on other sites More sharing options...
udaystrad Posted December 29, 2013 Author Share Posted December 29, 2013 (edited) k what i have found out is the IP which is been extracted is my Gateway IP and not client IP. Now i cant remov my gateway as i will loose my connection. i have tried sme settings but it has no effect....either nothings hapnenin or i m losing my connection. Pls if u can provide me with some solution to sort out this gateway issue or how to get the client IP if d above code doesnt work....... Thanks in advance.... Edited December 29, 2013 by udaystrad Quote Link to comment https://forums.phpfreaks.com/topic/284574-how-to-get-client-ip/#findComment-1463214 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.