remember user and password in browser

0

a question I am trying that when it logue and select in the checbox is recorded in the form this is the code I use

if(isset($_POST['recordarme']) && !empty($_POST['recordarme'])){
$dominio = $_SERVER["HTTP_HOST"];
setcookie("recordarme", $_POST['recordarme'], time()+3600, "/" , $dominio);
}
    
asked by Eduardo Palomino 16.06.2017 в 02:09
source

1 answer

2

Good There is an option in all forms of access to our email accounts, forums, blogs, etc. very famous for the function it offers. Remember user and password on this computer is something that many people use to avoid having to enter their credentials whenever you access a web page from your computer.

Although it can be a major security problem in the event of a loss or theft of the equipment, in all the access forms we can see this function.

What is a Cookie?

For the website to always recognize our username and password on a website, use cookies. For those who do not know, cookies are files created by the web pages where they store certain visitor information, whether they are preferences or information about their profile.

** Creating a cookie system **

To create a system that recognizes the user even when closing the browser and reopening it, we will use a file with the form and the checking of cookies, and another one of authentication.

In this exercise, to make it simpler and clearer, I will not focus on creating the user session or securing the identification.

The table, apart from the user's basic data, will have a field called cookie where we will store a random value to check the user's cookie.

In the file index.php, in the form we will put the user fields, password and also the check to remember password.

what you need is this:

if(isset($_COOKIE['id_user']) && isset($_COOKIE['marca'])){
	if($_COOKIE['id_user']!="" || $_COOKIE['marca']!=""){
		$sql_c = mysql_query("SELECT * FROM users 
					WHERE id_user='".$_COOKIE["id_user"]."' 
					AND cookie='".$_COOKIE["marca"]."'
					AND cookie<>'';");
	}
	if(mysql_num_rows($sql_c)){
		$row_c = mysql_fetch_array($sql_c);
		echo "El usuario ".$row_c['username']." se ha identificado correctamente.";
		$user_cookie = mysql_fetch_array($sql_c);
	}
}

I recommend that you see the complete tutorial on the author's website: Author

I also recommend that you read about: Cookies on the official php site: php documentation

but I also recommend using version 5 of PHP: PHP 5

also I invite you to see this tutorial that has the same code preo using Class, I leave it to the latter because in your code you can not see that you use OOP, but I also recommend that you use OOP in php this is the link : link

first of all I suggest you see this question on stackoverflow where they talk about cookies and their security: the question I hope it serves you.

    
answered by 16.06.2017 в 03:02