Different visitors show different content, the same visitor later access the content unchanged, except for clearing the cache.

Source: Internet
Author: User
For example
1. There are 5 items A, B, C, D, E, one of which will be displayed in one or more locations of the Web page.
2. When the first visitor visits the page, he sees a content, and when the visitor opens the page again, he sees content a, unless he clears the browser cache.
3. When the second visitor visits the page, he sees the B content, and when the visitor opens the page again, he sees content B unless he clears the browser cache.
4 、。。。
5, the sixth visitor to visit the page, see a content, in the future when the visitor opens this page, see is content a, unless he clears the browser cache.
6, the seventh visitor to the page, see the B content, in the future when the visitor opens the page, will see the content B, unless he clears the browser cache.
Like some loops

It is equivalent to each visitor from 5 content in order to take a display to the visitor, complete 5 after the loop.

How do you write the code for this function?


Reply to discussion (solution)

Save with cookies

$arr = Array (' A ', ' B ', ' C ', ' D ', ' E '), $file = ' data.log ';//Gets the page that is not displayed, if all is displayed, then re-assign if (file_exists ($file)) {    $data = Json_decode (file_get_contents ($file), true);    if (! $data) {        $data = $arr;    }} else{    $data = $arr;} Determine if the user has visited, such as the direct display of the last access results, or extract the first page, write user cookiesif (Isset ($_cookie[' show ')) {    $result = $_cookie[' show '];} else{    $result = Array_splice ($data, 0,1);    $result = Array_pop ($result);    Setcookie (' Show ', $result, Time () +3600);    File_put_contents ($file, Json_encode ($data), true);} echo $result;

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