master82 Posted September 29, 2006 Share Posted September 29, 2006 I'm developing a site and I want to implement a feature during the login phase that will allow me to keep track of the users IP address (for security and limiting users in certain ways around the site).I have created the table 'userIPs' with 3 fields:Userid - This will store the userid of the user who just logged inIP - This stored the IP of the users computerDate - The time the user logged inNow what I would like to do is record this information each time a user logs in, however, to stop the list getting too large I want to do the following:1. User logs in, all the details are recorded above.2a. Unon another login, if it is the same user/IP simply just update the date field.2b. Upon another login, if the user has different IP, record a new row with all the detail below.So basically I'll end up with a list of users and all the Ips they have used and when it was last used.Anyone know how this can be done or a better suggestion on how I could achieve this? Quote Link to comment https://forums.phpfreaks.com/topic/22482-ip-records/ Share on other sites More sharing options...
HuggieBear Posted September 29, 2006 Share Posted September 29, 2006 I agree with logging the details, that's a good idea, however, using the info to restrict areas/features of the site is not a good idea. As you've correctly identified (and it would appear made provision for) is that users IP's will probably change quite regularly.As for how you'd do it, just take a look at the [url=http://uk.php.net/manual/en/reserved.variables.php#reserved.variables.server]Predefined $_SERVER Variables[/url] area of the PHP manual.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/22482-ip-records/#findComment-100800 Share on other sites More sharing options...
master82 Posted September 29, 2006 Author Share Posted September 29, 2006 I had thought about that so was going to use a cron to delete records that are older than X.My primary use for it would be to simply spot multiple accounts. Then monitor them to see if they break any terms and conditions of the site.I know that users can simply use proxies, but a small monitoring system is better than none at all.Anyone point me in the right direction? Quote Link to comment https://forums.phpfreaks.com/topic/22482-ip-records/#findComment-100803 Share on other sites More sharing options...
HuggieBear Posted September 29, 2006 Share Posted September 29, 2006 [quote]Anyone point me in the right direction?[/quote]Did you look at the section I pointed you at? That will give you the information you need for getting the IP Address, I assumed you already had the code to insert into the database as you've got the database setup already.If you need info on entering data into the database then check out the manual section relating to your database (more than likely MySQL).RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/22482-ip-records/#findComment-100806 Share on other sites More sharing options...
master82 Posted September 29, 2006 Author Share Posted September 29, 2006 Sorry - completely missed that last line, but thankfully i already know how to get the users IP.I have not started the script yet, still perfecting the login authentication. But I'll have a go later and post if I have problems. Quote Link to comment https://forums.phpfreaks.com/topic/22482-ip-records/#findComment-100810 Share on other sites More sharing options...
acdx Posted September 29, 2006 Share Posted September 29, 2006 I'd suggest you simply add a "last login time" (datetime?) and a "last login ip" (varchar) column to your user table, defaulting to NULL. When someone logs in, "update users set logintime = xx, loginip = xx where id = xx". It's not like the users are gonna "go back to their old ip" anyway. Quote Link to comment https://forums.phpfreaks.com/topic/22482-ip-records/#findComment-100817 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.