What is a cookie
The server saves user information on the client, such as login name, password, etc. These data are like cookies Likewise, the amount of data is not large. The server can read it from the client when needed and save it in the client's browser cache directory.
① When the browser accesses cookie.php, the server will also send an http response with Set-Cookie:name=zxf;expire=Wed,21-Sep-2017 20:14 GMT. When the browser obtains After receiving this message, the cookie information will be saved to the local disk.
② If we do not have time (the third parameter) the cookie will not be saved to the client, and when the browser session ends, the cookie will expire.
③ The cookie saves string information
④ The client can save multiple keys=>val
⑤ During the saving process of the cookie, Chinese will be urlencoded Encoding
Cookies can have multiple key=>val, and different validity times can be set for different key values.
Instance:
Submit form page:
<?php $user = isset($_COOKIE['username'])?$_COOKIE['username']:''; ?> <form action="file.php" method="post"> 用户名:<input type="text" name="username" value="<?php echo $user; ?>" /><br /> 密码:<input type="password" name="pwd" /><br /> 记住用户名:<input type="checkbox" name="rem" value="1"><br /> <input type="submit" name="sub" value="提交"> </form>
Form information receiving page, set at the same time Cookie:
<?php $user = $_POST['username']; if($_POST['rem']){ setcookie("username",$user,time()+3600*3600*24); }else{ setcookie("username",'',time()-1); } echo "登录成功"; ?>
Recommended tutorial: PHP video tutorial
The above is the detailed content of How to save the username when logging in in 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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Chinese version
Chinese version, very easy to use

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
