@Ramiro Gonzalez Maciel 他说他已经制作了该脚本,他不需要框架作为示例。框架通常将脚本封装起来并放置在适当的位置。
回答这个问题:
我通常在cookie中存储一些md5字符串,这些字符串是由他的md5(密码)和他的用户名组合而成的,这样我下次他进入我已登录的网站时我就会知道,这样我就不会让他再次登录
我的例子:
<?php
$username = $_POST['username'];
$password = $_POST['password'];
// sql and escape stuff witch will return 1 if he has entered a valid login
if($sqlreturn == 1){
// do login
$wraplogin = md5($username."-".md5($password)."-".SECRET_KEY); // I always define a define('SECRET_KEY', 'mysecretkey'); in global file.
// now you can store that $wraplogin in cookies and remember his login. Next time he enters the website, you read that cookie, compare it with what you have in your database and let him in.
}
?>Run Code Online (Sandbox Code Playgroud)
现在我知道这不是最好的例子,但我个人在非常大的网站(> 500.000 用户)中使用过它,而且还没有一个被黑客入侵:)
这就是 cookie 在登录部分的优势。
祝你好运。