


Cookie control access authorization for beginners learning PHP
In formal projects, there will basically be applications with authorization control, such as RBAC permissions, etc. This article helps novices better understand PHP and use cookies by sharing how to use cookies to control access authorization.
<?php if(isset($_POST['name'])||isset($_POST['pass'])){ //如果有表单有提交 //检测表单中需要的值 if(empty($_POST['name'])){ die("请输入用户名!"); } if(empty($_POST['pass'])){ die("请输入密码!"); } //设置数据库变量 $host = "localhost"; $user = "root"; $pass = "zq19890319"; $db = "cookie"; //打开连接 $connection = mysql_connect($host, $user, $pass) or die("Unable to connect!"); //选择一个数据库 mysql_select_db($db) or die("Unable to select database!"); //建立一个查询 $query = "SELECT * FROM users WHERE name = '".$_POST['name']."' AND pass = SHA1('".$_POST['pass']."')"; //执行一个查询 $result = mysql_query($query) or die("Error in query:$query." . mysql_error()); //是否有记录集返回 if(mysql_num_rows($result) == 1){ //如果有一行记录返回 //表示验证已经通过 //建立一个session,设置一个登陆标记为1,并将当前用户名保存在cookie中 session_start(); $_SESSION['auth'] = 1; setcookie("username", $_POST['name'], time()+(84600*30)); echo "用户访问已经授权!"; }else{ echo "错误的用户名或密码!"; } //释放记录集 mysql_free_result($result); //关闭数据库 mysql_close($connection); } else{ //如果没有表单提交,则显示一个HTML表单 ?> <html> <head></head> <body> <center> <form method="post" action=""> 用户名<input type="text" name="name" value="<?php echo $_COOKIE['username'];?>" /> <p /> 密码<input type="password" name="password" /> <p /> <input type="submit" name="submit" value="登陆" /> </form> </center> </body> <?php } ?>
Related recommendations:
ThinkPhp RBAC experience_PHP tutorial
PHP learning to write the perpetual calendar
PHP learning CURL crawler example
The above is the detailed content of Cookie control access authorization for beginners learning PHP. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Mistlock Kingdom is an open world game where players can play as Sons of Fire to survive and explore. The game combines the unique entertainment of action RPG challenges, bringing players endless surprises and joy. In the game, players can explore resources, environments, weapons and more. Some novice players may be curious about how to get started with the game. In this introduction and sharing, we will provide you with some relevant getting started guides. Tips for Beginners to the Fog Lock Kingdom: The danger levels of areas shrouded by miasma are different. During the exploration process, new areas of the map will be gradually unlocked, and the location of the areas shrouded by miasma can be seen. The map will be distinguished by two colors. The blue area can be entered in a short time. The time you can stay will also be different depending on the character's ability level.

Cookies on your computer are stored in specific locations on your browser, depending on the browser and operating system used: 1. Google Chrome, stored in C:\Users\YourUsername\AppData\Local\Google\Chrome\User Data\Default \Cookies etc.

Cookies are usually stored in the cookie folder of the browser. Cookie files in the browser are usually stored in binary or SQLite format. If you open the cookie file directly, you may see some garbled or unreadable content, so it is best to use Use the cookie management interface provided by your browser to view and manage cookies.

Anchor Arrival is a 3D turn-based card game with a high-definition beautiful girl two-dimensional theme. It provides a rich and exciting combination of characters for players to explore and experience. It has many powerful combinations of high-quality lineups. New players are also curious novices. What powerful characters are recommended in the pool? Let’s take a look at the selection reference for novices to win ten consecutive golds! Anchor Point Advent is a powerful character recommendation for novice pools. The first ten-consecutive pick is Alice. She is mainly a single-target lightning-type burst character. The output is very explosive, and the experience will be very friendly to newcomers, so it is highly recommended to choose it. It is recommended to choose the combination of "Alice" + "Antelope" for 10 points. Alice is the most worthy character to output the goldpire attribute, and is not even a bit stronger than the other two characters in the novice card pool. Alice can pass special

Essential skills for newbies to PyCharm: Mastering the use of batch indentation requires specific code examples Overview: PyCharm is a powerful Python integrated development environment (IDE) that provides many practical tools and functions to help developers improve efficiency . In the daily coding process, we often need to indent the code to keep the code format neat and beautiful. The batch indentation function provided by PyCharm can help us quickly batch indent the code and improve coding efficiency. This article will explore Py

Crown of the Ancients is a high-quality and strategic card mobile game based on Western magical adventure. In-game secret exploration, ruins adventure, national championship and other special gameplay are waiting for you to experience. So for novice players, if they want to get started with this game quickly, a novice guide is indispensable. Today, the editor will bring you the relevant guide, let’s take a look. An overview of the Ancient Crown beginner’s guide, gameplay and area opening styles: 1. Diamond accumulation flow: Everything is focused on accumulating diamonds, and then you start to work hard after leaving the village. Except for the main magic weapon, three flywheel activities, etc., which require diamonds, the others are ignored. The main focus is on one of them. Don't pay attention to the hero challenge. You can fight as many as you can, and don't force it. Advantages: You only need to mess around to accumulate diamonds. After leaving the village, you can quickly access the latest activities with diamonds, get new series of hardware heroes, and diamonds are broken.

Cookies on the mobile phone are stored in the browser application of the mobile device: 1. On iOS devices, Cookies are stored in Settings -> Safari -> Advanced -> Website Data of the Safari browser; 2. On Android devices, Cookies Stored in Settings -> Site settings -> Cookies of Chrome browser, etc.

The dangers of cookie leakage include theft of personal identity information, tracking of personal online behavior, and account theft. Detailed introduction: 1. Personal identity information is stolen, such as name, email address, phone number, etc. This information may be used by criminals to carry out identity theft, fraud and other illegal activities; 2. Personal online behavior is tracked and analyzed through cookies With the data in the account, criminals can learn about the user's browsing history, shopping preferences, hobbies, etc.; 3. The account is stolen, bypassing login verification, directly accessing the user's account, etc.
