search
HomeBackend DevelopmentPHP TutorialDetailed explanation of SSI usage (2)_PHP tutorial

Detailed explanation of SSI usage (2)_PHP tutorial

Jul 13, 2016 pm 05:19 PM
includeSSItwouseCanOrderpictureBundleinsertletterdocumentDetailed explanation

2.Include command

The Include command can insert text or pictures from other documents into the currently parsed document, which is the key to the entire SSI. With the Include command, you only need to change one file to instantly update the entire site!

The Include command has two different parameters. If you use the wrong parameters to update the site, not only will you fail to achieve the original intention, but you will get a lot of error messages.

Virtual: gives the virtual path to a document on the server side. For example:

 $#@60;!--#include virtual="/includes/header.html" --$#@62;

In order to organize the content of the site more rationally, users can create an includes subdirectory in the root directory to store all included files. The Virtual parameter can inform the server that what is to be included is a virtual file, that is, the file and the currently parsed document are not located in the same directory, but are stored in other directories. The server will find the includes subdirectory in the root directory based on the value of this parameter. Using this method, users can put all files contained in HTML documents in one directory, and save different pages in different directories or subdirectories according to their relationship. No matter which document the server parses, it can find the included files without generating any errors.

But there is a small problem that needs to be solved. Generally, we will add some TITLE and META tags to the page. If we stipulate that all pages call the same header file, it will be very inflexible. When users encounter such a problem, they can use two include files, one to set the content before the TITLE tag, and the other to set the part after the META tag, and any custom content can be added between the two include files. For example:

$#@60;!--#include virtual="/includes/header1.html" --$#@62;
$#@60;TITLE$#@62;Your Page Title$#@ 60;/TITLE$#@62;
$#@60;LINK rel = STYLESHEET href = "http://domain.com/styles/my.css" Type = "text/css" $#@62;
$#@60;META NAME = "Description" CONTENT = " Description of page"$#@62;
$#@60;META NAME = "Keywords" CONTENT = "keywords for page" $#@ 62;
$#@60;!--#include virtual="/includes/header2.html" --$#@62;

Place page content here

$#@60;!--#include virtual="/includes/footer.html" --$#@62;

From the above we can see that including headers and footers in the page can greatly reduce the workload of site updates. But what if we want to dynamically display some content, such as the last updated time of the page? No problem, we can save the included file with the .html suffix, so that we can call other included files in the included file.

File: Give? The relative path of the current directory, in which "../" cannot be used, and absolute paths cannot be used. For example:

 $#@60;!--#include file="header.html" --$#@62;

This requires each directory to contain a header.html file. Of course, using this method is not much simpler than updating every page, but it is still very convenient if the user only updates one or two files. For example, if we don't want someone unfamiliar with HTML to directly change the news page on the website, we can just let him update a separate text file and then include the file into the HMTL document, so that it will not break The original page and updated content at the same time, the best of both worlds.

3.Echo:

The Echo command can display the following environment variables:

DOCUMENT_NAME: Displays the name of the current document.

 $#@60;!--#echo var="DOCUMENT_NAME" --$#@62;

The displayed result is:

index.html

DOCUMENT_URI: Displays the virtual path of the current document. For example:

 $#@60;!--#echo var="DOCUMENT_URI" --$#@62;

The displayed result is:

 /YourDirectory/YourFilename.html

As the website continues to develop, those longer and longer URL addresses will definitely cause headaches. If you use SSI, everything will be solved. Because we can combine the domain name of the website and the SSI command to display the complete URL, namely:

 http://YourDomain$#@60;!--#echo var="DOCUMENT_URI" --$#@62;

QUERY_STRING_UNESCAPED: Displays the query string sent by the client without escaping, in which all special characters are preceded by the escape character "". For example:

 $#@60;!--#echo var="QUERY_STRING_UNESCAPED" --$#@62;

DATE_LOCAL: Displays the date and time in the time zone set by the server. Users can customize the output information by combining the timefmt parameter of the config command. For example:

 $#@60;!--#config timefmt="%A, the %d of %B, in the year %Y" --$#@62;
 $#@60;!-- #echo var="DATE_LOCAL" --$#@62;

The displayed result is:

 Saturday, the 15 of April, in the year 2000

This news has a total of 2 pages, currently on page 1 1 2

DATE_GMT: The function is the same as DATE_LOCAL, except that the date is returned based on Greenwich Mean Time. For example:

 $#@60;!--#echo var="DATE_GMT" --$#@62;

LAST_MODIFIED: Displays the last update time of the current document. Similarly, this is very practical in SSI. Adding the following simple line of text to the TML document can dynamically display the update time on the page.

 $#@60;!--#echo var="LAST_MODIFIED" --$#@62;

CGI environment variables

In addition to SSI environment variables, the echo command can also display the following CGI environment variables:

SERVER_SOFTWARE: Displays the name and version of the server software. For example:

 $#@60;!--#echo var="SERVER_SOFTWARE" --$#@62;

 SERVER_NAME: Displays the server’s host name, DNS alias or IP address. For example:

 $#@60;!--#echo var="SERVER_NAME" --$#@62;

SERVER_PROTOCOL: Displays the protocol name and version used by the client request, such as HTTP/1.0. For example:

 $#@60;!--#echo var="SERVER_PROTOCOL" --$#@62;

SERVER_PORT : Displays the server’s response port. For example:

 $#@60;!--#echo var="SERVER_PORT" --$#@62;

REQUEST_METHOD: Displays the client’s document request method, including GET, HEAD, and POST. For example:

 $#@60;!--#echo var="REQUEST_METHOD" --$#@62;

REMOTE_HOST: Displays the name of the client host that issued the request information.

 $#@60;!--#echo var="REMOTE_HOST" --$#@62;

REMOTE_ADDR: Displays the IP address of the client that issued the request information.

 $#@60;!--#echo var="REMOTE_ADDR" --$#@62;

 AUTH_TYPE: Displays the user identity verification method.

 $#@60;!--#echo var="AUTH_TYPE" --$#@62;

REMOTE_USER: Displays the account name used by the user who accessed the protected page.

 $#@60;!--#echo var="REMOTE_USER" --$#@62;

4.Fsize: Displays the size of the specified file. The output format can be customized by combining the sizefmt parameter of the config command.

$#@60;!--#fsize file="index_working.html" --$#@62;

5.Flastmod: Displays the last modification date of the specified file, and can be combined with the timefmt parameter of the config command to control the output format.

$#@60;!--#config timefmt="%A, the %d of %B, in the year %Y" --$#@62;
$#@60;!-- #flastmod file="file.html" --$#@62;

Here, we can use the flashmod parameter to display the update date of all linked pages on a page. Here’s how:

$#@60;!--#config timefmt=" %B %d, %Y" --$#@62;
$#@60;A HREF="/directory/file.html" $#@62;File$#@60;/A$#@62;
$#@60;!--#flastmod virtual="/directory/file.html" --$#@62;
$#@60;A HREF="/another_directory/another_file.html"$#@62;Another File$#@60;/A$#@62;
$#@60;!--#flastmod virtual ="/another_directory/another_file.html" --$#@62;

The displayed result is:

File April 19, 2000
Another File January 08, 2000

Some readers may think that two links are so complicated and not convenient at all. In fact, if there are 20 or more links on the page, and each link is updated regularly, you can see the use of blastmod to display the modification date.

6.Exec

The Exec command can execute CGI scripts or shell commands. How to use:

Cmd: Use /bin/sh to execute the specified string. If SSI uses the IncludesNOEXEC option, this command will be blocked.

Cgi: Can be used to execute CGI scripts. For example, in the following example, the counter.pl script in the cgi-bin directory of the server is used to place a counter on each page:

$#@60;!--#exec cgi="/cgi-bin/counter.pl" --$#@62;

This news has a total of 2Page, currently at page 2 1 2

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532650.htmlTechArticle2.Include command The Include command can insert text or pictures from other documents into the currently parsed document. It is the key to the entire SSI. Only one file needs to be changed through the Include command...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP in Action: Real-World Examples and ApplicationsPHP in Action: Real-World Examples and ApplicationsApr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: Creating Interactive Web Content with EasePHP: Creating Interactive Web Content with EaseApr 14, 2025 am 12:15 AM

PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

PHP and Python: Comparing Two Popular Programming LanguagesPHP and Python: Comparing Two Popular Programming LanguagesApr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

The Enduring Relevance of PHP: Is It Still Alive?The Enduring Relevance of PHP: Is It Still Alive?Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP's Current Status: A Look at Web Development TrendsPHP's Current Status: A Look at Web Development TrendsApr 13, 2025 am 12:20 AM

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP vs. Other Languages: A ComparisonPHP vs. Other Languages: A ComparisonApr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP vs. Python: Core Features and FunctionalityPHP vs. Python: Core Features and FunctionalityApr 13, 2025 am 12:16 AM

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

PHP: A Key Language for Web DevelopmentPHP: A Key Language for Web DevelopmentApr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MantisBT

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.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),