Different visitors display different content. the access content of the same visitor remains unchanged in the future, except for clearing the cache.

Source: Internet
Author: User
Different visitors display different content. the access content of the same visitor remains unchanged in the future, except for clearing the cache. For example
1. there are five content A, B, C, D, and E, one of which will be displayed in one or more locations on the webpage.
2. after the first visitor visits the webpage, he will see content A. When the visitor opens the webpage again, he will see content A unless he clears the browser cache.
3. after the second visitor visits the webpage, he will see B's content. when the visitor opens the webpage again, he will see B's content unless he clears the browser cache.
4 ,...
5. after the sixth visitor visits the webpage, he will see the content of A. When the visitor opens the webpage again, he will see content A unless he clears the browser cache.
6. after the seventh visitor visits the webpage, he will see B's content. when the visitor opens the webpage again, he will see B's content unless he clears the browser cache.
Such as loops

It is equivalent to getting one visitor from 5 items in order to show the visitor. After 5 items are retrieved, they are recycled.

How to write the code for this function?


Reply to discussion (solution)

Save using cookies

$ Arr = array ('A', 'B', 'C', 'D', 'E'); $ file = 'data. log'; // Obtain the page that has not been displayed. if all pages are displayed, the value if (file_exists ($ file) {$ data = json_decode (file_get_contents ($ file) is assigned again ), true); if (! $ Data) {$ data = $ arr ;}} else {$ data = $ arr;} // determines whether the user has accessed the service. if the user has accessed the service, the last access result is displayed, otherwise, extract the previous page and write the user cookiesif (isset ($ _ COOKIE ['show']) {$ result = $ _ COOKIE ['show'];} else {$ result = array_splice ($ data, 3600); $ result = array_pop ($ result); setcookie ('show', $ result, time () + ); 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.