How to achieve staticization in php: 1. Rewrite the access address and change it through the PATHINFO mode of the URL; 2. The site can be staticized through a certain program before the user accesses the site.
How to achieve static php:
During the development process of PHP site, because search engines search for PHP pages There is a certain difference between the inclusion of deer and HTML pages. For the promotion of the site or the needs of SEO, the site must be made static to a certain extent. Staticization does not mean that there are no animation and other elements in the page, but it means that the html code of the webpage is in the page. There is no need to execute server-side languages such as PHP scripts. We can directly access the webpage. This is a static web page.
One way is to rewrite the access address, which can be changed through the PATHINFO mode of the URL. Make it look more like a static page. Therefore, there is a greater chance of being crawled and included by search engines, but it is more friendly to search engines and pseudo-static.
The second is that the site can be made static through a certain program before the user accesses the site. Generate static pages. When the user visits this page. Because you are accessing a static page, the access speed will be many times faster than accessing a dynamic page. The front-end performance is that the page loading speed becomes faster, and the back-end performance is that the database connection is reduced. It reduces the pressure on the database. The only disadvantage is that it takes up more hard disks and the hard disks are relatively cheaper.
Pure static is the way to generate HTML files. We need to enable PHP's own caching mechanism, that is, ob_start to enable caching. And there cannot be any output before ob_start, otherwise the operation will fail. Then we use the ob_get_contents function to get the content in the cache, which will return a string. The third function is ob_end_clean, which is used to clear the contents of the cache and close it. It returns True on success and False on failure.
<?php //开启缓存 ob_start(); //第一步连接数据库 $conn = mysqli_connect("localhost","root","","bbs"); //第二步设置对应的字符编码 $setting = 'set names utf8'; mysqli_query($conn,$setting); //第三步进行查询 $sql = 'SELECT * FROM user'; $result = mysqli_query($conn,$sql); //第四步把查询结果转化为一个数组 $rows = mysqli_num_rows($result); $sqldata = array(); for($i = 0;$i <$rows;$i ++){ $sqldata[] = mysqli_fetch_assoc($result); } //然后打印该信息 var_dump($sqldata); //得到生成的html文件,下次訪问就无需訪问数据库了 $msg = ob_get_contents(); ob_end_clean(); //把输出内容放入一个html文件里 $f = fopen("static.html","w"); fwrite($f,$msg); echo "静态化成功";
Generate an html file in the directory
<pre class='xdebug-var-dump' dir='ltr'> <b>array</b> <i>(size=6)</i> 0 <font color='#888a85'>=></font> <b>array</b> <i>(size=4)</i> 'id' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'1'</font> <i>(length=1)</i> 'level' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'0'</font> <i>(length=1)</i> 'name' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'辛星'</font> <i>(length=6)</i> 'pwd' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'bd04fcc97578ce33ca5fb331f42bc375'</font> <i>(length=32)</i> 1 <font color='#888a85'>=></font> <b>array</b> <i>(size=4)</i> 'id' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'2'</font> <i>(length=1)</i> 'level' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'1'</font> <i>(length=1)</i> 'name' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'小倩'</font> <i>(length=6)</i> 'pwd' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'61cb72858be523b9926ecc3d7da5d0c6'</font> <i>(length=32)</i> 2 <font color='#888a85'>=></font> <b>array</b> <i>(size=4)</i> 'id' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'3'</font> <i>(length=1)</i> 'level' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'1'</font> <i>(length=1)</i> 'name' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'小楠'</font> <i>(length=6)</i> 'pwd' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'a3d2de7675556553a5f08e4c88d2c228'</font> <i>(length=32)</i> 3 <font color='#888a85'>=></font> <b>array</b> <i>(size=4)</i> 'id' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'4'</font> <i>(length=1)</i> 'level' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'1'</font> <i>(length=1)</i> 'name' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'刘强'</font> <i>(length=6)</i> 'pwd' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'fcdb06a72af0516502e5fdccc9181ee0'</font> <i>(length=32)</i> 4 <font color='#888a85'>=></font> <b>array</b> <i>(size=4)</i> 'id' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'5'</font> <i>(length=1)</i> 'level' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'1'</font> <i>(length=1)</i> 'name' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'星哥'</font> <i>(length=6)</i> 'pwd' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'866a6cafcf74ab3c2612a85626f1c706'</font> <i>(length=32)</i> 5 <font color='#888a85'>=></font> <b>array</b> <i>(size=4)</i> 'id' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'6'</font> <i>(length=1)</i> 'level' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'1'</font> <i>(length=1)</i> 'name' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'辛勇'</font> <i>(length=6)</i> 'pwd' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'e93beb7663f3320eaa0157730d02dd0c'</font> <i>(length=32)</i>
Related learning recommendations: php programming (video)
The above is the detailed content of What is the static method in php. For more information, please follow other related articles on the PHP Chinese website!

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Linux new version
SublimeText3 Linux latest version