Use of cookies

Source: Internet
Author: User

When logging in using cookies, when landing the page, in the browser to write a cookie, indicating that you have logged in, with the permission to login, by default, this cookie is valid during the browser opening, when the browser reopened, need to login again, of course, You can also set the lifecycle of a cookie to allow the cookie to function after a few seconds, so that it can be destroyed during browser opening or destroyed during shutdown, mainly to see if the time is reached, and the cookie is stored in the browser. By default, only the sibling and sibling directories of the cookie and the pages of the directory can be accessed, of course, can be set in that directory can be accessed, set the cookie with the Setcookie () function, receive cookies with super Global array $_cookie to obtain

Setcookie (cookie name, cookie value, life cycle unit seconds, which directory can be accessed, domain name suffix);

Get that cookie with $_cookie[' cookie name '];

Easy to print history with cookies

<?php$uri=$_server[' Request_uri '];if (!isset ($_cookie[' history ')) {$his []= $uri;} else{$his =explode (' | ', $_cookie[' history '); Echo ' Jdaso '; Print_r ($his); Array_unshift ($his, $uri); $his =array_ Unique ($his);//Remove Duplicate if (count ($his) >10) {Array_pop ($his);}} Setcookie (' History ', implode (' | ', $his)),//print_r (Implode (' | ', $his));//print_r ($_cookie); $id =isset ($_get[' id ']) ? $_get[' id ']:0;//print_r ($his);? ><p><a href= "cookie.php?id=<?php echo $id-1?>" > Prev </a></p><p><a href= " cookie.php?id=<?php echo $id +1?> "> Next </a></p><ul><li> Browsing History </li><?php foreach ($his as $v) {><li><?php echo $v;? ></li><?php  }?></ul>

Use of cookies

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.