Jump to content

Archived

This topic is now archived and is closed to further replies.

master82

IP records

Recommended Posts

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 in
IP - This stored the IP of the users computer
Date - The time the user logged in

Now 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?

Share this post


Link to post
Share on other sites
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.

Regards
Huggie

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
[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).

Regards
Huggie

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.