HTML / PHP Detect if form value changed

Posted on

Coding Problem :

I have a form where I can change things like username , password , morada , etc.
On the site I also use a session (login) for each user, which is defined by username .
The problem is that by changing the form value of username it no longer equals the username of the current session, so that the login stops working.
Is there something I can use to detect the change from username to redirect to the login page again and display an alert saying “Username changed, sign in again”?

    

asked by anonymous 27.04.2015 / 11:35

Answer :


Answer 1 :

Probably in your code there is a button to send the change in the username, what you can do is: after the page that changes the username in the database ends, you make a redirect

if (mysqli_query($con,$sql))
    print "<script>
    alert('username alterado bla bla')
location.href='página de login.php'
</script>";

location.href = ‘login page.php’ > This part that does the redirect

    


Answer 2 :

Since the user name can be changed it is recommended that you identify the session by the user ID of the database, which would not generate conflict if the same login is open in two different sessions, as the name itself says, the ID is an identifier mechanism. The user, e-mail, document number, etc., because they are unique can also be used, but it is not recommended if these values can be changed because of situations like these.

    


Answer 3 :

You can give a session_start (); making it generate a single session for each browser even if used by the same username in different browsers, each one will have a different session, what you can do is how I do it in my applications, you generate the session each time the user logs in in the login and when passing by the password checker, takes the session and poê within a logins log and if unnecessary a log, changes the field next to the user’s table, that is, when logging in, you can choose

1) Get the session and put it in a login log table with SESSION, DATA and USERNAME.

2) takes the session and changes the user’s session into the user table itself.

and then when it does user change, create a session along with that tells the browser that this happened through the session stored in the database, then check if they are the same, if not, it redirects to login, if you want more details, I can show you a practical code.

    


Answer 4 :

I suggest the use of token:

Once the user logs in, you generate the token and save to the DB and session.

$token = md5(uniqid(rand(), true));

When you log off you remove the token from the DB and so the user must log in again.

Any changes to the user name will not affect the token.

I hope I have helped.

    


Answer 5 :


Answer 6 :


Answer 7 :


Answer 8 :


Answer 9 :

Leave a Reply

Your email address will not be published.