About PHP Syntax (4) _php tutorial

Source: Internet
Author: User
Body:
The above ("Talk about PHP grammar (3)" At the end of the mention of the cookie and session, this article on these two techniques for some introduction.
Cookies we often read it as "library", also called it "small dessert." It is a small file stored in the customer's browser. It is developed to address a single connection to HTTP without Queensland unlimited memory and can be used to track users or to confirm users who return. PHP provides a setcookie () function that allows you to set a cookie. Because cookies are part of the Queensland unlimited HTTP header. Therefore, the Setcookie () function must be called before the Web page data is passed to the browser. This is the same as calling the header () function.
Cookies must be provided by the host side, so we must send a cookie-setting header in the CGI program. The following is an example of a Queensland unlimited in PHP that calls the Setcookie () function to set a cookie:
Setcookie ("User", "Wind", Time () +3600, "/php/", "http://www.oso.com.cn");
?>
Where user is the name of the cookie, wind is the value of the cookie, time () +3600 is the period of validity of the cookie,/php/is the relevant path to the cookie, http://www. Queensland Unlimited oso.com.cn is the site of the cookie.
In fact, in addition to using this method to set cookies, we can also use the header () function such as: Header ("Set-cookie:user=wind"), but this to the HTTP head of the letter Queensland Unlimited to understand the line, so I do not recommend this way, It is easier to use Setcookie ().
When a cookie is read, the browser automatically checks to see if there is a cookie on the site, and some words are automatically passed to the server, and in PHP, the CO Queensland unlimited Okie is returned as a variable. When the cookie set above returns, a $user variable is formed, which is the value of wind.
However, the cookie has a fatal disadvantage, that is, if the client closes the cookie and cannot store the cookie to the client, everything will go wrong. Therefore, the S Queensland Unlimited Ession is provided in PHP4 to replace the cookie.
The most important difference between a session and a cookie is that the cookie is stored on the client and the session is stored on the server side. In fact, the session is a global Queensland unlimited variable that provides a PHP script. Examples are as follows:
Set a session, named user, with a value of wind
Session_Start ();
$user = "Wind";
Session_register ("user");
?>
Read the session and show the result as "welcome you!" Wind
Session_Start ();
echo "Welcome you!" $user ";
?>
This article only discusses the cookie and session technology, for those who want to know more about the technology, please refer to other books.
--(to be continued)--

http://www.bkjia.com/PHPjc/315392.html www.bkjia.com true http://www.bkjia.com/PHPjc/315392.html techarticle text: Above ("Talk about PHP grammar (3)" At the end of the mention of the cookie and session, this article on these two techniques to make some introductions. Cookies we often read it as "library", also called it "small ...

  • 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.