Overblog
Edit post Seguir este blog Administration + Create my blog

TecnoSetfree

TecnoSetfree

Un Blog encargado en compartir temáticas de tecnología, how to, hack y programación. Aquí encontraras temas diversos y proyectos que puedes adquirir y/o diseñar a tu manera.


how to make login form in php and mysql - Part II

Publicado por Setfree activado 26 Junio 2020, 16:07pm

Etiquetas: #how to, #ajax php y mysql, #php

login php mysql with session

how to make login user with php and mysql

It is important to know how to manage PHP sessions to apply them to different web projects, so we will learn how to Login with PHP and MySQL with sessions. Not without first inviting you to review the post on how to add users to the MySQL database.

 

Making user login php

Create the following files:

login.html

checklogin.php

panel-control.php

logout.php

 

 

login.html file

 

Login.html

Login.html

In this file, we create a form in the modal window style and add two inputs: username and password, where we will effectively ask the user for their credentials and send them to checklogin.php to validate the fields and then move on to the desired user profile .

 

checklogin.php

checklogin.php

checklogin.php

We start the script by adding a login and the connection data, then the data from the login.html is taken, verifying that they exist in the database.

$ username = $ _POST ['username'];
$ password = $ _POST ['password'];

$ sql = "SELECT * FROM $ tbl_name WHERE username = '$ username'";

If all goes well, the session data is stored and redirected to the control panel. Otherwise the user must return to login.

Something new that we will find in the file is the time to deactivate the session for idle time:

$ _SESSION ['expire'] = $ _SESSION ['start'] + (5 * 60);

We set the time to 5 minutes, then the user must log in again for security reasons.

 

panel-control.php

panel-control.php

panel-control.php

A small control panel is accessed for the user to view their data, reports, etc. Here you add what you want the user to see in their profile.

Something very important is that the session time started is monitored at every moment. After 5 minutes it will be closed due to inactivity.

A php logout button is also added, which calls the logout.php file that runs the following code:

 

<?php

session_start();
unset ($SESSION['username']);
session_destroy();

header('Location: http://localhost/Login/login.html');

?>

 

With this file you will be able to close the user and address the login page again or another section if you prefer:

header ('Location: http: //localhost/Login/login.html');

Do you have questions or comments about it? Write us for further assistance.

 

Download all project

Para estar informado de los últimos artículos, suscríbase:

Archivos

¡Somos sociales!

Ultimos Posts