How can I achieve the login status after entering the php account on the page?

Source: Internet
Author: User
How can I achieve the login status after entering the php account on the page? Urgent! After entering the account and password on the php login page, there is a checkbox followed by a message indicating that the logon status is maintained (remember the account and password, and then log on to the website again after the browser is closed, directly go to the page, instead of entering the account and password again.) how can this be achieved? How can I achieve the login status after entering the php account on the page? Urgent!
After entering the account and password on the php login page, there is a checkbox followed by a message indicating that the logon status is maintained (remember the account and password, and then log on to the website again after the browser is closed, directly go to the page without entering the account and password again)

How can this be achieved? Is there any simple instance code? thank you!

------ Solution --------------------
Google php + cookie usage.
------ Solution --------------------
The general process is as follows: after successful login, write the cookie, set the validity period, visit this page next time, and check whether the cookie is valid. if it is valid, directly jump to the relevant page, if not, go to the login page.
------ Solution --------------------
What is Cookie?

Cookies are often used to identify users. Cookie is a small file that the server stays on the user's computer. When the same computer requests a page through a browser, it sends a cookie at the same time. With PHP, you can create and retrieve the cookie value.

How to create a cookie?

The setcookie () function is used to set the cookie.

Note: The setcookie () function must be locatedBefore the tag.

Syntax

Setcookie (name, value, expire, path, domain );
Example

In the following example, we will create a cookie named "user" and assign it "Alex Porter ". We also stipulate that the cookie will expire in one hour:

Setcookie ("user", "Alex Porter", time () + 3600 );
?>




Note: When sending a cookie, the cookie value is automatically URL encoded and automatically decoded during retrieval (to prevent URL encoding, use setrawcookie () instead ).

How can I retrieve the Cookie value?

The $ _ COOKIE variable of PHP is used to retrieve the cookie value.

In the following example, we retrieve the cookie value named "user" and display it on the page:

// Print a cookie
Echo $ _ COOKIE ["user"];
// A way to view all cookies
Print_r ($ _ COOKIE );
?>
In the following example, we use the isset () function to check whether the cookie has been set:



If (isset ($ _ COOKIE ["user"])
Echo "Welcome". $ _ COOKIE ["user"]. "!
";
Else
Echo "Welcome guest!
";
?>


How to delete a cookie?

When deleting a cookie, you should change the expiration date to the past time point.

Example of deletion:

// Set the expiration date to one hour ago
Setcookie ("user", "", time ()-3600 );
?>
What if the browser does not support cookies?

If your application involves a browser that does not support cookies, you have to use other methods to pass information from one page to another in the application. One way is to pass data from the form (the content about the form and user input is described earlier in this tutorial ).

The following form submits user input to "welcome. php" when the user clicks the submit button:






Retrieve the value in "welcome. php" as follows:



Welcome .

You are Years old.


------ Solution --------------------
1000 yuan is a four-digit betting website in front of the seven-star lottery, with reference to the website. Do not disturb me if you have the ability to answer the mark, or the scammers do not disturb me. Connect QQ: 1298581873

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.