用COOKIE保存登录用户信息时,怎样保证COOKIE不被伪造解决办法

WBOY
Release: 2016-06-13 10:17:46
Original
1374 people have browsed it

用COOKIE保存登录用户信息时,怎样保证COOKIE不被伪造
各位高手。请教大家一个问题,我想使用COOKIE保存用户登录,目的是可以在HTML页面使用(显示用户名和自动填入文本框),和能够在一段时间内免登录。
请问一下。我怎样才能保证COOKIE不会被伪造呢?

------解决方案--------------------
选择记住密码登录的时候
$spuerpass="20120412001@#" //自己更改,用户无法获得
$user_id=$rows_arr['user_id'];
$rand=md5(md5($user_id.$spuerpass));
setcookie('user_,$user_id,(time()+2592000),'/','',0);
setcookie('rand',$rand,(time()+2592000),'/','',0);
$_SESSION['user_id']=$user_id;


下次打开页面检测是否有记住密码登录
if(isset($_COOKIE['user_id'])&&isset($_COOKIE['rand']))
{
$user_id=$_COOKIE['user_id'];
$spuerpass="20120412001@#";
$rand=md5(md5($user_id.$spuerpass));
if($_COOKIE['rand']==$rand)
{
$_SESSION['user_id']=$user_id;
}
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!