Jump to content

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?
Link to comment
https://forums.phpfreaks.com/topic/22482-ip-records/
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
Link to comment
https://forums.phpfreaks.com/topic/22482-ip-records/#findComment-100800
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?
Link to comment
https://forums.phpfreaks.com/topic/22482-ip-records/#findComment-100803
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
Link to comment
https://forums.phpfreaks.com/topic/22482-ip-records/#findComment-100806
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.
Link to comment
https://forums.phpfreaks.com/topic/22482-ip-records/#findComment-100817
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.