Example of php cookie authentication login

WBOY
Release: 2016-07-25 08:56:17
Original
818 people have browsed it
This article shares a piece of PHP code to learn a simple method of using cookies to implement login verification. Friends in need can refer to it.

php uses cookies for login verification. The code is as follows:

<?php
// 登录验证,重置用户名
unset($username);
if ($_COOKIE['login']) {
    list($c_username,$cookie_hash) =
    split(',',$_COOKIE['login']);
    if (md5($c_username.$secret_word) == $cookie_hash) {
        $username = $c_username;
    } else {
        print "You have sent a bad cookie.";
    }
}

//登录验证
if ($username) {
    print "Welcome, $username.";
} else {
    print "Welcome, anonymous user.";
}
?>
Copy after login


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