O
O
Outsider V.2015-04-05 19:34:05
PHP
Outsider V., 2015-04-05 19:34:05

In which method to determine user data?

So, there is a UserOperator class, which, among other things, is responsible for the user logging in. It has the following methods:
1) getUser() - getting a user from the database by login/password. If the login / password according to the database did not match, this method pulls another method:
2) writeFailedAttempt () - a method for recording an unsuccessful login attempt (in the database, of course), which should record the entered login, user agent and IP.
There are also:
3) getRealIP method returns visitor's IP.
4) the getUserAgent method returns the visitor's user agent.
What puzzled me: there are several options:
1. Define ip and useragent in the getUser() method, that is, immediately pull writeFailedAttempt($login, $this->getRealiP(), $this->getUserAgent()) .
2. Define ip and user agent already inside the writeFailedAttempt() method.
3. Define all this in the class constructor, moving the bodies of the getUserAgent() and getRealIp() methods there and writing the values ​​into the corresponding properties of the object.
4. Assign values ​​to properties also in the constructor, but do it using the appropriate methods (do not transfer the bodies of the methods to the constructor).
I just do not know what principle to follow here, and therefore I cannot determine which option is the most correct.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FanatPHP, 2015-04-05
@FanatPHP

The problem is much easier than you think.
First, you don't need to define a user agent - it's not needed by any means for writeFailedAttempt.
You don't need any "RealIp". If you want to write down the IP address of the client, then you must write only $_SERVER['REMOTE_ADDR'] and nothing else.
And to access a global variable, no function is needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question