In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
What are the skills of PHP Cookie login authentication? for this question, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.
The construction purpose of a website is the integrity of the function. One of the functions is the implementation of user login authentication. Next we will give you a detailed introduction to the relevant implementation methods of PHP Cookie login authentication.
Example of PHP Cookie login authentication code:
Login
User name:
Password:
Cookie save time:
Browser process
Save for 1 day
Keep it for 30 days
Keep it for 365 days
< ?php @mysql_connect("localhost", "root","1981427") //选择数据库之前需要先连接数据库服务器 or die("数据库服务器连接失败"); @mysql_select_db("test") //选择数据库mydb or die("数据库不存在或不可用"); //获取用户输入 $username = $_POST['username']; $passcode = $_POST['passcode']; $cookie = $_POST['cookie']; //执行SQL语句 $query = @mysql_query("select username, userflag from users " ."where username = '$username' and passcode = '$passcode'") or die("SQL语句执行失败"); //判断用户是否存在,密码是否正确 if($row = mysql_fetch_array($query)) { if($row['userflag'] == 1 or $row['userflag'] == 0) //判断用户权限信息是否有效 { switch($cookie) //根据用户的选择设置cookie保存时间 { case 0: //保存Cookie为浏览器进程 setcookie("username", $row['username']); break; case 1: //保存1天 setcookie("username", $row['username'], time()+24*60*60); break; case 2: //保存30天 setcookie("username", $row['username'], time()+30*24*60*60); break; case 3: //保存365天 setcookie("username", $row['username'], time()+365*24*60*60); break; } header("location: main.php"); //自动跳转到main.php } else { echo "用户权限信息不正确"; } } else { echo "用户名或密码错误"; } ?>Example of PHP Cookie login authentication code:
< ?php session_start(); if(isset($_COOKIE['username'])) { @mysql_connect("localhost", "root","1981427") //选择数据库之前需要先连接数据库服务器 or die("数据库服务器连接失败"); @mysql_select_db("test") //选择数据库mydb or die("数据库不存在或不可用"); //获取Session $username = $_COOKIE['username']; //执行SQL语句获得userflag的值 $query = @mysql_query("select userflag from users " ."where username = '$username'") or die("SQL语句执行失败"); $row = mysql_fetch_array($query); //获得用户权限信息 $flag = $row['userflag']; //根据userflag的值输出不同的欢迎信息 if($flag == 1) echo "欢迎管理员".$_SESSION['username'] ."登录系统"; if($flag == 0) echo "欢迎用户".$_SESSION['username'] ."登录系统"; echo "< a href="logout.php" href="logout.php">Write off
< /a>"
}
Else
{
Echo "you do not have permission to access this page"
}
? >
< ?php setcookie("username"); echo "注销成功"; ?>The answer to the question about PHP Cookie login verification skills is shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.