How does PHP implement clicking the browser's return button to refresh the page when it returns to the page?

Source: Internet
Author: User
The search on the Internet is ASP php how to prevent the back button cache it?

Reply content:

The search on the Internet is ASP php how to prevent the back button cache it?

    1. Unable to block browsing history.back() behavior

    2. You can consider setting the page as no cache

      $nocache = array(    'Expires' => '0',    'Cache-Control' => 'no-store,private, post-check=0, pre-check=0, max-age=0',    'Pragma' => 'no-cache');foreach($nocache as k => $v)    header($k.': '.$v);
    3. If you really want to reject the back, you can use the following method to simulate, consider a jump, so back again , will automatically jump to the current page, similar to the refresh

      header('Location: index.php');

Take the homepage page link to say:
3
Search engine crawler will be based on the href access to the /index.php?page=3 3rd page of data, conducive to SEO.
Users in the browser right-click "Open in New tab" also can access to/index.php?page=3.
If the user clicks the link directly on the page, the Click event is triggered, the local data is loaded and rendered by JS via Ajax, and the Location.hash is set to /index.php#/page/3 .
location.hash = "#/page/3";
The browser can remember Location.hash history, we only need to listen to Location.hash changed events hashchange (support IE8, not support IE7/6) can realize the user click the Browser Back button when the page reload.

$(window).on("hashchange", function(){    alert(location.hash); //输出#/page/2    var arr = location.hash.split("/"); // ["#", "page", "2"]    if(arr[1] == "page") {        page(arr[2]); //AJAX局部加载第2页数据        //location.href = "/index.php?page="+arr[2]+"&"+new Date().getTime(); //直接访问第2页    }});

Above this "SEO and experience of the hyperlink design" should be able to meet the landlord needs, but the need for a certain cost of transformation.

Page loading complete JS Refresh page location.href = Location.href

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