PHP static HTML pages

Source: Internet
Author: User
This article mainly introduces PHP static HTML pages, shares the advantages of static processing methods and static processing, and provides various static methods, for more information, see

This article mainly introduces PHP static HTML pages, shares the advantages of static processing methods and static processing, and provides various static methods, for more information, see

Currently, many websites need to be statically processed during construction. Why does the website need to be statically processed? We all know that a pure static website is an independent html page for all webpages. When we access the website, we can directly read the file without data processing, and the access speed can be imagined, it is also a friendly method for search engines.
How does a pure static network stand on a website?
The page file at the end of the website, so pure static websites need more space, but actually the space is not much, especially for small and medium-sized enterprise websites, technically speaking, it is difficult for large websites to achieve pure static content for the whole site, and the generation time is too long. However, small and medium websites are still compared with pure static websites, which has many advantages.

How does a dynamic website perform static processing?
Static pages refer to converting dynamic pages into html/htm static pages. Dynamic Pages are generally compiled by programming languages such as asp, php, jsp, And. net, which is easy to manage. However, when accessing a webpage, the program must first process the webpage, resulting in a relatively slow access speed. Static Page access is fast but not easy to manage. Static dynamic pages can combine the benefits of the two pages.

What benefits does static processing bring to websites?

Static pages are more easily indexed by search engines than dynamic pages.

Accessing static pages does not need to be processed by a program, so it can improve the running speed.

Reduce the burden on the server.

HTML pages are not affected by Asp vulnerabilities.

Websites with static processing are relatively secure compared to websites without static processing, because static websites are not the first choice for hacker attacks, it is difficult for hackers to launch attacks from static pages on the front-end without knowing your background system. At the same time, it also has a certain degree of stability. For example, if a database or website program has a problem, it will not interfere with the page after static processing, and will not open the page because of the impact of the program or data.

Search engine spider programs prefer such websites, which can also reduce the workload of spider programs. Although some people think that the search engine is capable of capturing and identifying dynamic websites, we recommend that you make static URLs as much as possible.

Next we will mainly talk about the concept of page static, and hope to help you!
What is HTML static:

The static page can be divided into two types:Pseudo-static, That is, url rewriting.True static.
In PHP website development, full-site or partial static processing is required for website promotion and SEO. PHP provides multiple methods to generate static HTML pages, for example, static pages are implemented using PHP templates and cache.
PHP staticIt means that pages generated by websites are displayed in the form of Static HTML in front of visitors. PHP static is divided into pure static and pseudo static. The difference between PHP and PHP is that the processing mechanism for generating static pages is different.
PHP pseudo-static:Use Apache mod_rewrite to implement URL rewriting.

Benefits of static HTML:

I,Reduces the burden on the server. You do not need to call the system database to browse the Web page.
II,It is conducive to SEO optimization by search engines. Both Baidu and Google will give priority to static pages, not only quick but also full;
III,Speed up page opening. Static pages do not need to be connected to databases. The speed of opening static pages is significantly higher than that of dynamic pages;
IV,Websites are more secure. HTML pages are not affected by vulnerabilities related to php programs. A bigger website is basically a static page, which can reduce attacks and prevent SQL injection. When a database error occurs, normal Website access is not affected.
V,When a database error occurs, normal Website access is not affected.
The most important thing is to increase access speed and reduce the server load. When the data volume is tens of thousands, hundreds of thousands, or more, you know which one is faster and is easy to find by search engines. Although generating html articles is difficult to operate and complicated in the program, these sacrifices are worth the effort to make it easier for search and make it faster and safer.

Static HTML policies and examples:
Basic Method
File_put_contents () function
Use php built-in cache mechanism to achieve static page-output-bufferring.

Method 1: Use PHP templates to generate static pages

It is very convenient to implement static PHP templates, such as installing and using PHP Smarty to implement static websites.
When Smarty is used, the page can also be static. The following describes how to use Smarty to dynamically read data.
Generally, the following steps are taken:
1. Pass a parameter (ID) through the URL );
2. query the database based on this ID;
3. After obtaining the data, modify the display content as needed;
4. Data to be displayed for assign;
5. display template file.
In the static process of Smarty, you only need to add two steps in the above process.
First, use ob_start () to open the buffer before 1.
Second, use ob_get_contents () after 5 to get the content not output in the memory, and then use fwrite () to write the content to the target html file.

According to the preceding descriptions, this process is implemented on the website's front-end, while content management (ADD, modify, and delete) is usually performed on the background to make effective use of the above process, you can use a small method, that is, Header (). The specific process is as follows: after adding or modifying a program, use Header () to jump to the foreground to read the program. In this way, the page can be HTML-based, and then jump back to the background management side after html is generated, the two jump processes are invisible.

Method 2: Use the PHP file read/write function to generate a static page

<? $ Out1 ="PHP static website tutorialWelcome to PHP website development tutorial. This article mainly introduces the static PHP website page method."; $ Fp = fopen (" leapsoulcn.html "," w "); if (! $ Fp) {echo "System Error"; exit () ;}else {fwrite ($ fp, $ out1); fclose ($ fp); echo "Success" ;}?>

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.