Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I am making the website of a law firm. In a table of the database I store data as which user accesses the application, when it is connected and when it is disconnected. I wonder if it would be complex to know since ip the user has connected to be able to store it, thanks.


What I have tried:

Sorry but i don't know how to start
Posted
Updated 6-Mar-20 2:16am

Getting the visitor's IP address is relatively simple: you just need to check the HTTP_X_FORWARDED_FOR and REMOTE_ADDR server variables:
php - How to get Real IP from Visitor? - Stack Overflow[^]

NB: In some cases, the IP address might be classified as PII under GDPR. You will need to check whether your solution complies with the relevant regulations.
 
Share this answer
 
Comments
Member 14765215 7-Mar-20 19:05pm    
I will work on your idea, thank you very much. I will comment on my results.
You'd need a login system - IP addresses don't uniquely identify a user.

As far as internet IP addresses go, they are "shared" by all users who connect through the same router for example - so everyone in a company is likely to have the same IP address. And unless the user (or his company) has selected and paid extra for a static IP address then even that is "shared" - each time the router is power cycled you may or may not be using the same IP address afterward.

For LAN IP addresses, it's even worse as they are commonly pooled, and allocated on a "first come, first served" based when a device connects to the router / hub.

So relying on IP addresses to uniquely identify users is a poor idea - it's far, far too easy to get the wrong person!

What you need is a good solid user login system, combined with software in your app and / or your DB to record user accesses in a separate table: the user, a timestamp, and what they accessed goes into a audit log table. If you combine this with individual logins for SQL (which restrict what the user can do to only what they are allowed, SQL can maintain these audit logs for you: SQL Server Audit (Database Engine) - SQL Server | Microsoft Docs[^]

Don't expect this to be a ten minute job: anything to do with security needs very careful planning in advance, or you can trip yourself up far, far to easily, and either leave yourself vulnerable, or find yourself locked out of your own system.
 
Share this answer
 
Comments
Member 14765215 7-Mar-20 19:04pm    
Thanks for answering. I have not explained myself well, I have a login system with username and password, what I want to achieve is to store which user has logged in, when, until when and since what ip.
I understand that the IP does not identify a user, but it would be valuable if it were necessary to investigate a conflicting access.
Hi, I've been researching and how I'm going to use laravel the most effective solution is to use the method
authenticated()
from class
LoginController

Request->getClientIp()
thanks for helping
 
Share this answer
 

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