How to use cookies to implement the login interface in php: 1. Set the login form; 2. Set the default value of the text box to the content in the cookie; 3. Add an if judgment to the form processing interface.
#The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
How to use cookies to implement login interface in php? The PHP login interface uses cookies to remember account passwords
Interface effect:
cookie principle:
cookie in The server creates it and returns it to the client browser for local storage. The cookie storage time is determined by setting the life cycle.
Implementation process:
<!-- 登录表单 --> <div class='div_login' id='login'> <form name='login_form' method="post" action="/FirstPHPWeb/application/controllers/loginCl.php"> <!-- 在此处设置文本框默认值为 cookie 中的内容 --> 账 号:<input type="text" name="id" value="<?php echo @$_COOKIE['id']; ?>"/><br/> 密 码:<input type="password" name="psw" value="<?php echo @$_COOKIE['psw']; ?>"/><br/> 验证码:<input type="text" name="checkcode" /><br/> <img src="/static/imghwm/default1.png" data-src="../controllers/createCheckCode.php" class="lazy" id='login_checkcode_img' onclick="changeCode('login_checkcode_img')" alt="How to use cookies to implement login interface in php" ><a href="#" onclick="changeCode('login_checkcode_img')">看不清楚,换一张</a><br/> <input type="checkbox" name="isKeepInfo" value="keep" checked/>在此电脑上保留用户名<br/> <input class='btn' type="image" src='/FirstPHPWeb/public/img/login.png' alt='submit' name='login' value='登陆' /> </form>
// 在表单的处理界面添加判断 if($isKeepInfo){ setcookie("id", "$id", time()+3600*24*7,'/'); setcookie("psw", "$psw", time()+3600*24*7,'/'); }
Details:
It is not complicated to implement this function, but In actual application, a small detail will also be ignored:
Let’s first learn about the setcookie function. The following syntax is given in the development document:
setcookie(name, value, expire, path, domain);
name, value: store cookie data in the form of key-value pairs;
expire: expiration time, timestamp format (optional). If not set, it defaults to a session-level cookie, and the cookie will expire after the browser is closed.
path: Valid path on the server side (optional). The default is the path of the page when the cookie is currently set;
domain: the domain name that the cookie is valid for (optional). Only the specified domain name can get the cookie. By default, all domain names can get it. [Recommended learning: PHP video tutorial]
When the form file and form processing file are not in the same directory, be sure to remember to set the path attribute, otherwise it will be taken in the form interface. Cookie username and password do not exist.
The above is the detailed content of How to use cookies to implement login interface in php. For more information, please follow other related articles on the PHP Chinese website!

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct


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

Atom editor mac version download
The most popular open source editor

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

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

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

SublimeText3 Chinese version
Chinese version, very easy to use