Best way to save login data

Asked

Viewed 934 times

0

Good afternoon, what would be the best way to save a user’s login data? I have a PHP login system that validates user and password via ajax and if everything is ok, I want to save the data (email in case) to be used in other points of the system. I thought about using session, but I don’t think we can create/record a session with javascript, so I thought about localStorage but I don’t think it would be safe. What would be the best way? I use PHP, jquery, ajax and javascript. Grateful.

  • Use SESSION php.

  • Thanks for the reply, I thought about it, but as I use ajax for a refresh-free login of the page, I do not know how I would save a session considering that javascript does not handle ajax.

3 answers

1


In the validation of ajax you can already set the variables with the database data. I’m going to make a very small example just to illustrate the use of Session, which saves the php

After validating the data in the database save the name, login, and any other variable you want in session

session_start();
$_SESSION["codigo_usuario"] = $query[1];
$_SESSION["nome_usuario"] = $query[2];
$_SESSION["permissao"] = $query[3];
$_SESSION["email"] = $query[4];

And to recover the desired data just call it, for example if you want to know the permission just call the session correspondent.

$_SESSION["permissao"];

And when the user drops from the system you destroy the session with the command:

session_destroy();

This way you can store session data, do not use session passwords, they can be captured if the encryption level is easy to break.

0

The best way to save login (and the same one used in several frameworks) is certainly Session. I save my projects in session whenever a user logs in or drops out of the site.

A website that can clarify a better way to use the superglobal $_SESSION[] will be in the references.

Proper use of Sessions without the use of frameworks

0

Friend recommend the use of a framework in the back-end, I am using in several projects Codeigniter, the framework itself takes care of the whole process of login, registration and authentication.

It already takes care of storing user data as well as maintaining a table called ci_sessions to save sessions.

On top of this framework it is possible to build multiple applications, authenticating users in several different applications on the same database.

https://codeigniter.com/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.