PHP uses cookies for automatic login

Source: Internet
Author: User
Tags set cookie
PHP uses cookies for automatic login. Code highlighting produced by Actipro CodeHighlighter (freeware)
Http://www.CodeHighlighter.com/

--> 1 2 // automatic login
3 if ($ _ COOKIE ["userName"] & $ _ COOKIE ["password"])
4 {
5 // Obtain the login information and pass it into the database for verification
6
7 // Print logon information
8 echo 'user name: '. $ _ COOKIE ["userName"].'
Password: '. $ _ COOKIE ["password"];
9}
10
11
12
13 // submit the form
14 if ($ _ GET ['submit '])
15 {
16 // echo 'login .. ';
17 // select "remember password" to write user login information to the cookie.
18 if ($ _ GET ['member'] = 'on ')
19 {
20 setcookie ("userName", $ _ GET ["userName"], time () + 3600 );
21. setcookie ("password", $ _ GET ["pass"], time () + 3600 );
22}
23
24 // refresh the page
25 echo' Location. href = "cookie. php" script ';
26}
27
28 // log out
29 if ($ _ GET ['out'])
30 {
31 // Set cookie timeout
32 setcookie ("userName", $ _ GET ["userName"], time ()-3600 );
33 setcookie ("password", $ _ GET ["pass"], time ()-3600 );
34
35 // refresh the page
36 echo' Location. href = "cookie. php" script ';
37}
38?>
39
40
41
42
43 Input information
44User name
45Password
46 Remember password
47
48 Log out
49

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.