How do you write this code about cookies? Solutions

Source: Internet
Author: User
Tags setcookie
How do you write this code about cookies?
The problem is this:
For example, there are 3 pages of qq.html, baidu.html, so.html, and then randomly open one of them from the rand.php.

How to add a cookie control, within the set time range (such as 24 hours), the same user each time only open the same page, For example, the user opens the baidu.html at random for the first time, so the next time they visit, they will still only open baidu.html, not qq.html and so.html.

------to solve the idea----------------------
if (isset ($_cookie[' url ')) {
Header (' Location: '. $_cookie[' url ')];
}else{
$URLARR = Array (' qq.html ', ' baidu.html ', ' so.html ');
$urlId = Array_rand ($URLARR, 1);
Header (' Location: '. $URLARR [$urlId]);
Setcookie (' url ', $url, Time () +24*3600);
}
------to solve the idea----------------------

$arr = Array (' qq.html ', ' baidu.html ', ' so.html ');
$page = ";
if (Isset ($_cookie[' page ')) {
$page = $_cookie[' page '];
}else{
$page = $arr [Mt_rand (0,2)];
Setcookie (' page ', $page, Time () +86400);
}
echo file_get_content ($page);
  • 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.