PHP page static

Source: Internet
Author: User

in many places have seen the full station of PHP static, strange bluffing. In fact, you will be static a page, then don't say the whole station, want to static how much can. So the key is, first of all to know how to static a page, understand the principle of static is the key. Here's my personal understanding.   First, you need to know several functions. Ob_start (); Ob_end_clean (); ob_get_contents (); file_put_contents ();//This can be fopen,fwrite instead of file_exists (); etc function. If you do not know these functions, go through the manual, there is not much to explain. Ok. The following is the process of the build:   Assume that you need to generate the current page into a.html. So  ------------------------------------------------------//Now here's a place to stay,,,,,,,,,,,,,,,,,,,,,,,,,,, remember some commas ~~~//first need to use OB _start ();//The function of this is to not let the content of the current dynamic page be sent to the client. Since it is not allowed to send, then the content how to get, as follows. $content =ob_get_contents ();//$content is all the content of your current page. is temporarily saved in server memory. After you get the content, you can release the content Ob_end_clean ();//Good, write the previous content directly to the file. This is also the key to generate static pages file_put_contents ("a.html", $content);//has been OK before. See if you have a a.html in your catalogue. Remember these full periods .......... ...........  ------------------------------------------  Generate static pages, many places are redirected directly to the new page. A.html-----Header ("location:a.html"). The statement is written in a lot of periods where I personally think it is unnecessary. Because the current page has been dynamically generated, why redirect once?   Okay, here's the problem. So how does the generated static page work?   Well, go back and look at a lot of comma places. We start with a judgment at the beginning of the current page. Determine if the a.html exists. Redirect to a.html if it exists. The code is as follows  --------------------------------------------if (file_exists ("a.html")) {   $time = time ();     //This is to judge the static page generation time, we may need to periodically update the static page-after all, dynamic page is to change it.    if ($time-filemtime ("a.html") < 30*60)    {   header ("location:a.html");   }} ------------------------------------------------------good. The above basically can be done to generate static pages.    of course, if you want to complete static pages, as well as static file rules, you have to design the---not all of the static page files are called a.html.  

We can name them based on the values passed by the current dynamic page. ~

PHP page static (GO)

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.