Dynamic pages in PHP. PHP. Dynamic page creation Write a page in php



So, friends, if you have reached this lesson, then you have managed to either install a local server or buy a hosting where you can work with PHP. Congratulations - that's a big step!

I will say briefly about PHP - this programming language is used all over the world and you can create sites of all levels of complexity on it, from business card sites to large portals. I think it is no longer a secret for many that the largest social media facebook.com(from scratch in php) and vk.com(engine in php) were written in PHP. So let's draw conclusions and start working!)

How the code works

PHP code processed on the server side. That is, there is no finished page. For example, in the code the command is given to collect data on how many users are currently registered on the site. Website visitor clicks on a link All users. He wants to get dynamic data, that is, those that are constantly changing. After the calculation on the server is completed, data will come from the server in the form of a generated HTML code of the page with the number of users. As a result, after clicking-request on the link, the user receives the page. If you view the code of the resulting page, you can see only HTML, and the PHP code will not be available for viewing. Roughly speaking, PHP is instructions to the server on how and from which blocks to make a page.

What does PHP code look like and where should I paste it?

PHP code can be embedded directly into HTML. PHP code is embedded in HTML pages using angle brackets and a question mark , however, you can restrict yourself to brackets with question marks . You will only need to change the file extension, for example from .html on .php

PHP code(file index.php)



PHP example


echo "Hello world!";
?>



Demonstration Download sources
The result of the code will be the output of plain text Hello World!. Ask why write php code to display plain text? echo statement, which we'll talk about a little later, is needed for more than just displaying text. More often, echo is used to display the result of some function that performed a calculation or took data from a database (What is a Database?). That is, for dynamic data display.

echo statement in PHP

As you already understood, the operator echo needed for data output. We take the content (in our case, only text so far) in quotes and end with a semicolon ; this marks the end of the operator's work.

In programming, when creating the first page, it is customary to use the phrase Hello World!- that is Hello World! That is what we use. In the example, we will not use html, since this is not necessary.

PHP code

echo "Hello World!";
?>
The program will output Hello World!.
In the very first example, we inserted a small php code into html. Now, on the contrary, let's embed html elements into the php code.

PHP code

echo " ";
echo " ";
echo " My first PHP script";
echo "";
echo " ";
echo "

Hello World!

";
echo "";
?>
As a result, we get an empty page with a title Hello World!

print statement in PHP

Unlike the echo statement, print outputs data including spaces and text breaks. Has some limitations - you can use only one argument, echo multiple. It takes longer than echo. In the future, we will resort to this operator when writing functions.

print "Hello World!
The second line of text"; // the result will be displayed in two lines
?>
The text will be displayed in the same way as it is written.

Output statement - PHP heredoc syntax

As you have already noticed, displaying a page by constantly using the echo statement is ugly and unreadable. Therefore, to output large parts of html code, there is another output statement using the heredoc syntax. It also outputs the data in the same form as it was (spaces and hyphens).

echo<<

Example


An example of outputting a large amount of text using html


The second paragraph of the same voluminous text.


HERE;
?>

Reminder for the lesson

PHP code can:

1. not contain any html element. The page and text will still be displayed. html is needed for beautiful content markup.

2. be both included in the html code and contain it inside their output statements (echo, print, etc.). The main thing is not to forget the design

3. pages with php code must have the appropriate extension: .php .phtml

From the next lessons, we will analyze the basics of creating websites in php, in which you will see all the advantages of using this language!

Thank you for your attention!

In the last lesson, we figured out what blocks the trip template will consist of, so you can get started. Let's start by creating two folders:

images - this folder will contain any image files used to style the template. Because we don’t have any design developments yet, then throw any one graphic file into this folder, otherwise Joomla will not install the template and will give an error if the folder is empty.

ATTENTION: Content graphics cannot be placed in the images folder of the template!

css - this folder will contain cascading style sheet files. To begin with, let's place an empty template.css file in it, with the help of which various design styles will be assigned to the site elements.

Next, you can start creating the most important index.php file, which will determine the visual location of the site elements and tell the Joomla CMS in which block to place various components and modules. The file is a combination of PHP and HTML.

I always use only Macromedia Dreamweaver when writing code. An excellent program, I strongly advise it to beginners, because. if you make a mistake while working on the code, the program will definitely highlight your jamb.

On the site you will find a tutorial on Macromedia Dreamweaver. If you are going to develop websites, then this program should be mastered, at least at the initial level, in order to edit template codes without errors.

Positioning of elements (blocks) of the page is done using HTML code, specifically we will use DIV tags. But the way our site will work on the Joomla engine, i.e. it will be dynamic, you will also have to use the PHP language. With its help, we will determine in which blocks the positions for displaying modules will be located, and how these positions will be called, whether the blocks will collapse or not. Let's connect style sheets from external files, content language, set how the site size will change, etc.

index.php

File header

The file header consists of several parts. The first part of the PHP header code is to make sure the file is not accessed directly for security reasons.

< ?php
defined ("_JEXEC" ) or die ;
JHtml::_("behavior.framework" , true ) ;
$app = JFactory::getApplication() ;
?>
< ?php echo "< ?" ; ?> xml version="1.0" encoding=" < ?php echo $this-> _charset ?> "?>

DOCTYPE is a very important parameter based on which the browser decides how to display this page and how to interpret the CSS.

< ! DOCTYPE html PUBLIC "- / / W3C/ / DTD XHTML 1.0 Strict/ / EN""http: / / www.w3.org/ TR/ xhtml1/ DTD/ xhtml1-strict.dtd">

The following snippet retrieves the installed language from the global configuration.

< html xmlns= "http://www.w3.org/1999/xhtml" xml:lang=" < ?php echo $this->language; ?>" lang=" < ?php echo $this->language; ?>" dir=" < ?php echo $this-> direction; ?>" >

The following is a code snippet that includes additional information for the header, which is set in the global configuration. You can see this information by looking at the source code of any web page. In particular, these are the meta tags that you already know about.

< head>
< jdoc:include type= "head" / >

The following lines in the header contain links to the main Joomla CSS styles.

< link rel= "stylesheet" href= "< ?php echo $this-> baseurl ?> /templates/system/css/system.css" type="text /css" / >
< link rel= "stylesheet" href= "< ?php echo $this-> baseurl ?> /templates/system/css/general.css" type="text /css" / >

To use the template design styles, we make a link to the file containing the cascading style sheets template.css, which is located in the CSS folder. It does not matter that this file is still empty, the main thing is to connect it, we will deal with the design later when we install the template on Joomla. This will make it easier to see the result.

< link rel= "stylesheet" href= "< ?php echo $this-> baseurl ?> /templates/< ?php echo $this-> template ?> / css/ template.css" type="text /css" / >

The following code snippet allows us to collapse the left or right columns if there are no modules in the "left" and "right" positions. If both columns are collapsed, then the content takes up 100% of the page width. If only one column is included, then the content takes up 80%. With two columns included, content accounts for 60% of the page width.

< ?php
if ($ this-> countModules("left and right" ) == 0) $contentwidth = "100" ;
if ($ this-> countModules("left or right" ) == 1) $contentwidth = "80" ;
if ($ this-> countModules("left and right" ) == 1) $contentwidth = "60" ;
?>

Header close

< / head>

< body>

The “page” block contains the design of only the page of the site, it will be the width of 950px.

< div id= "page" >

The "top" block is located at the very top of the page and contains two blocks "logo" and "user1".

< div id= "top" >

In the “logo” bokeh, we will place the logo graphic file, this will be written in the style sheets. But we write the automatic output of the site name in the index.php file, and the name is placed in the H1 tag, which is very important for search engine optimization.

< div id= "logo" >
< h1> < ?php echo $app - >getCfg("sitename") ; ?>< / h1>
< / div>

Let's define the position "user1" in the block of the same name to display the site search module.

< div id= "user1" >
< jdoc:include type= "modules" name= "user1" style= "xhtml" / >
< / div>
< / div> < ! - - конец блока top - - >

Output of the horizontal menu module in the "user2" block at the "user2" position. The block will collapse if there is no module at that position.

< ?php if ($this-> countModules("user2") ) : ?>
< div id= "user2 " >
< jdoc:include type= "modules" name= "user2" style= "xhtml" / >
< / div>
< ?php endif ; ?>

Next comes the site header block "header". In it, we will define the position "header" for the output of modules. The block will collapse if there is no module at that position. I intentionally expanded the capabilities of this block in order to be able to place in it not only the header image, but also image rotators.

< ?php if ($this-> countModules(" header") ) : ?>
< div id= "header">
< jdoc:include type= "modules" name= "header" style="xhtml" />
< / div>
< ?php endif ; ?>

In the "user3" block, define the position "user3" for displaying modules.

The block will collapse if no module is displayed at this position "user3".

< ?php if ($this-> countModules("user3") ) : ?>
< div id= "user3" >
< jdoc:include type= "modules" name= "user3" style= "xhtml" / >
< / div>
< ?php endif ; ?>

The block of the left column opens, which will collapse if there is no module in the “left” position.

< ?php if ($this-> countModules("left" ) ) : ?>
< div id= "left" >
< jdoc:include type= "modules" name= "left" style= "xhtml" / >
< / div>
< ?php endif ; ?>

The most important block of content opens, which can take up 100% of the page width, 80% and 60%, depending on the number of columns included.

< div id= "content< ?php echo $contentwidth ; ?> " >

Displaying messages in components

< jdoc:include type= "message" / >

Content output.

< jdoc:include type= "component" style= "xhtml" / >
< / div> < ! - - конец блока контента- - >

The block of the right column opens, which will be collapsed if there is no module in the “rigth” position.

< ?php if ($this-> countModules("right") ) : ?>
< div id= "rigth" >
< jdoc:include type= "modules" name= "right" style= "xhtml" / >
< / div>
< ?php endif ; ?>

Output of the "footer" block, designed to display the "HTML code" module with copyright information. You can also place a bottom horizontal menu or a content presentation module here. The block will collapse if more than one module is not displayed in this position of "footer"

< ?php if ($this-> countModules("footer") ) : ?>
< div id= "footer" >
< jdoc:include type= "modules" name= "footer" style= "xhtml" / >
< / div>
< ?php endif ; ?>

The site page block "page", body and all code are closed.

< / div> < ! - - конец блока page- - >
< / body> < ! - - конец блока body - - >
< / html> < ! - - конец кода- - >

We have created a complete index.php file. Now you know with what commands and in what order the template blocks are displayed.

ATTENTION: In order for the template code to be read from the joomla admin panel, the index.php file must be opened in the AkelPad editor and saved in UTF-8 encoding, while unchecking BOM. If you used the Macromedia Dreamweaver program to work with the file, then you need to select "Edit" > "Page Properties" in the return menu and select the Unicode document encoding (utf-8), while unchecking "enable Unicode signatures (BOM)". However, I strongly advise you not to edit the code from the Joomla admin panel, if you screw up something - there is no turning back, unlike the Macromedia Dreamweaver program, where you can always undo the changes made.

The very design of the blocks will be described in template.css. But we will customize the style sheets after installing the template on Joomla 3 (joomla 2.5), and for this you need to create

To create a promising, expandable and effective site of any complexity, you should start with a simple one. This process is not easy, it requires certain basic knowledge of PHP and MySQL, but if you look at it point by point, you can draw up a kind of “work plan” that will come in handy when creating new sites. Let's prepare the "core" and the base for the project. At first, it will be a regular business card site, but then, by adding functionality, it can be turned into anything. So let's get started.

1. Database preparation. Create the first table in the MySQL database

Create a new database, for example "mysite". Personally, I'm used to working with UTF-8 encoding, so I'll make a reservation right away: make sure that all text files of the site, the database itself, tables and table fields are in the same encoding.
Create a table in a new database. Let's call it "pages". This table will store the static pages of the future site and information about them. The table must contain the following fields:

  • page_id - page ID (SMALLINT, primary key, auto_increment);
  • page_alias - page alias for the CNC address string (VARCHAR, 255);
  • page_title - title of the page in the browser window (VARCHAR, 255);
  • page_meta_d - page meta description for the meta description tag (VARCHAR, 255);
  • page_meta_k - meta keywords for the meta keywords tag (VARCHAR, 255);
  • page_h1 - page title (VARCHAR, 255);
  • page_s_desc - short description material, for example, if the site materials will be in the form of a blog (TEXT);
  • page_content - the main text of the page, which will be displayed in the central column of the site (TEXT);
  • page_publish - contains "Y" if the page is published, or "N" if it is hidden (CHAR, default is "Y").

Immediately after creating the table, insert the values ​​​​for the main page of the site into it. In the "page_alias" field for the main page, I suggest inserting the value "home". Meta tags - according to the theme of the entire site. In the same way, you can create other pages, for example, "About the company" with the "about" alias and its own meta tags, or "Contacts" with the "contacts" alias, etc.

2. Create a site configuration file

In the root folder of the site, which should be empty at this stage, we create a “cfg” folder, in it, using .htaccess, we close access with the “deny from all” directive. Create a core.php file with the following content:

// MySQL
class MyDB
{
var $dblogin = "root"; // YOUR DATABASE LOGIN
var $dbpass = ""; // YOUR DATABASE PASSWORD
var $db = "mysite"; // NAME OF THE BASE FOR THE SITE
var $dbhost="localhost";

var$link;
var$query;
var $err;
var $result;
var$data;
var $fetch;

Function connect() (
$this->link = mysql_connect($this->dbhost, $this->dblogin, $this->dbpass);
mysql_select_db($this->db);
mysql_query("SET NAMES utf8");
}

function close() (
mysql_close($this->link);
}

Function run($query) (
$this->query = $query;
$this->result = mysql_query($this->query, $this->link);
$this->err = mysql_error();
}
function row() (
$this->data = mysql_fetch_assoc($this->result);
}
fetch() (
while ($this->data = mysql_fetch_assoc($this->result)) (
$this->fetch = $this->data;
return $this->fetch;
}
}
function stop() (
unset($this->data);
unset($this->result);
unset($this->fetch);
unset($this->err);
unset($this->query);
}
}

This file currently contains only a simple database connection class, but in the future you can add various useful functions to it that will be available from anywhere in the site code. Don't forget to change your username and password for your database.

If you are working on a Windows environment, I can recommend using the . This editor has line numbering, and it easily translates text from one encoding to another. ATTENTION! If you work in UTF-8 encoding - convert files to UTF-8 without BOM - this will help to avoid problems in the future.

3. Create index.php - the main site controller

The configuration file has been created. Now we create index.php in the root folder of the site - this will be the main script of the site, a kind of "main controller". Contents of the index.php file:

define("INDEX", ""); // SET MAIN CONTROLLER CONSTANT

Require_once($_SERVER."/cfg/core.php"); // CONNECT THE CORE

// CONNECT TO DB
$db = new MyDB();
$db->connect();

// MAIN CONTROLLER
switch ($_GET) (
case "page":
include($_SERVER."/com/page.php");
break;
default:
include($_SERVER."/com/home.php");
break;
}

Include($_SERVER."/template.php");
$db->close();

The $_GET variable will tell the main controller which site component to load on request. Now our site has only two components: “page” and “main page” (in principle, you can get by with one component for displaying a regular page, but often the look of the main page of the site differs from the usual pages of menu items). The logic of the main controller is as follows: the name of the required component (the value of the $option variable) is extracted from the URL string, depending on its value, the file of the component itself is included (contained in the /com folder). The component file does all the necessary work, retrieves data from the database and writes it to variables to be passed to the design template. At the very end, the site design file is connected, into which all the variables and data extracted in the components are transferred. This sounds a lot more complicated than it works.

4. Create a normal page output component

In the root of the site, create a folder "com" - it will store the component files. A site component, in my understanding, is a file in which data is processed for different sections of the site. For example, the component of a regular page retrieves the title, description, and text of the material from the database and writes them to the variables $title, $meta_d, $meta_k, $content, etc. This data is then transferred to the design template (you can create your own design template for each component ) and displayed to the user as an HTML page. For example, a catalog component that can be created in the future would do almost the same thing, but with data about products - and there are their own specifics, other fields in the table, and so on. Therefore, for each functional section of the site, it is worth creating a separate component. In the MVC (Model-View-Controller) scheme, the component plays the role of a model.

Create a file "page.php" in the "com" folder. The contents of the file are as follows:

/* PAGE COMPONENT */
$alias = $_GET;
$query = "SELECT * FROM pages WHERE page_alias="".$alias."" AND page_publish="Y" LIMIT 1";
$db->run($query);
$db->row();
// COMPONENT VARIABLES
$id = $db->data;
$alias = $db->data;
$title = $db->data;
$h1 = $db->data;
$meta_d = $db->data;
$meta_k = $db->data;
$s_desc = $db->data;
$component = $db->data;
// IF THE PAGE DOES NOT EXIST
if (!$id) (
header("HTTP/1.1 404 Not Found");
$component = "ERROR 404! This page does not exist";
}
$db->stop();

5. Create the Home Page Display Component

The main page in our database is stored under the pseudonym "home", and so far it does not differ in its structure from the usual pages of the site - it's just an article. Nevertheless, we will create a separate component for it - for the future, so to speak.


The content of the "home.php" component in the "com" folder is almost the same as the content of the normal page component, except for the query string to the database and the name of the component. The query string now looks like this:

$query = "SELECT * FROM wx_pages WHERE page_alias="home" LIMIT 1";

6. Create a design template for the entire site

Create a template.php file in the root of the site. In fact, this is a normal web design layout in HTML + CSS format, only with PHP variables in the right places. Insert between title tags, in the central column of the site insertand so throughout the template we place the necessary variables that are declared in the components.

The root folder should also have "css" and "images" folders for design elements. In the file /css/style.css - you can customize the styles to your liking.

7. Clean links and .htaccess file

To create clean links, I use mod_rewrite with direct instructions for the rules for each component separately, since parsing the address bar using the controller itself is considered unnecessary functionality. The content of .htaccess at this stage is:


Rewrite Engine On
RewriteBase /

RewriteCond %(REQUEST_FILENAME) !-d
RewriteCond %(REQUEST_FILENAME) !-f

# FORBIDDEN FILES
RewriteRule .htaccess - [F]
RewriteRule template.php - [F]

# mod_rewrite RULES
RewriteRule page/(+)([\/](0,1))\.htm$ index.php?option=page&alias=$1 [L]

In the future, we will add rules for the search components, catalog, articles blog, etc. There is only one point: to convert links like "mysite.com/index.php?option=pages&alias=about" into a link like "mysite.com/pages/about.htm" - looks pretty nice. In development, try to avoid the $_GET array for safety reasons and don't rely on it. It is advisable to store only parameters for the main controller ($option variable) and for the component ($alias variable) in it.

Also, in each folder of the site, “just in case”, create an empty index.html file - this is necessary so that nothing is displayed when accessing the directory through the address bar.

Tags: php, mysql, site engine, controller, site creation, mvc

There are a huge number of websites on the Internet. All these sites can be divided into two types: static and dynamic. Today we will talk about creating dynamic pages, but first I would like to tell you what a static and dynamic site (page) is.

Static sites

Static sites are made up of static web pages. This means that no matter what the user does, the page always looks the same. Such pages are stored on the server as HTML documents. Static pages are laid out manually. If you need to change the content of a page, then you have to edit the HTML code for each page.

Advantages:

  • Simplicity and cheapness of creation, undemanding to hardware resources;

Flaws:

  • Large time spent on editing content;
  • Not suitable for large projects.

Dynamic sites

Dynamic sites consist of dynamic web pages that can respond to user actions and change. Such pages are formed by the web server from several files (templates). All information is stored in a database. When a user requests a page, the relevant information is retrieved from the database, inserted into the template to form the web page, and sent by the web server to the user's browser. Thus, when updating the content of the site, you just need to add the text for the new page, which is then inserted into the database using a certain mechanism.

Advantages:

  • Content management is done through special forms where you can easily add, edit and delete information;
  • Maximum efficiency when adding new content to the site;
  • When adding or editing content, no special knowledge of web-mastering (HTML, CSS) is required;
  • Ability to create large multifunctional projects;
  • Great opportunities for promotion.

Flaws:

  • High cost of creation and maintenance;
  • You need to have the appropriate knowledge to maintain the performance of the site.

Now I think you understand that it is best to make a website using dynamic pages. it is the best and convenient choice. Well, now let's talk about creating dynamic pages.

Simple Links

Before learning the PHP language, I think you should already know HTML and of course creating hyperlinks. I would like to remind you:

$link = "example.php"; print"<а href = \"$link\">An example of a dynamic hyperlink.
\n"

This is how easy it is to create a dynamic hyperlink using the php language.

The process of creating a dynamic page

The process of creating a dynamic page consists of several stages:

Laying out the frame of the page. Let's call the page index.php - it will consist of parts: header (header), footer (footer), left menu(leftmenu). In this example, I will show how a table-based page is laid out, but you can also use a block verst.

1. Forming a file header.php.

Dynamic page in PHP.

Site header


2. We form a file leftmenu.php.

  • Link 1
  • Link 2
  • Link 3
  • Link 4
  • Link 5

3. We form a file footer.php.

Site Footer


Create a folder called template to which you will copy the resulting files. If you need to edit the header, left menu or footer of the site, you will know that the templates of these parts of the site are in this folder.

Let's connect the received files (templates) to the site using the include statement on the example of the index.php page.

Hello!

This is the first dynamic page in PHP.

This is how the index.php page is a dynamic page, it will be formed from several files (templates). You can make any number of such templates. If you need to change any part of the site, just find the desired template file and edit it.

This completes the creation of dynamic pages. I think you understand the meaning and practicality of dynamic sites and based on my example, you can create a large project. And don't forget to comment your code - it's very important friends! Good luck to you!

P.S. Small changes from 07/06/2019:

Since programming is always evolving, therefore, it must evolve at the speed of light. The tabular layout shown above is little used in practice nowadays and is only necessary for studying by novice programmers.

If you want to create new and effective websites, then we recommend using block layout instead of tabular layout. Let's consider in more detail.

Tables were invented specifically for displaying tabular data, and not for marking up page elements. What is in the table:

text

can be represented as a block (div) layout:

text

it takes up much less disk space.

Consider the advantages of block layout compared to tabular:

  1. A significant reduction in page size, usually 2-3 times, which significantly reduces the loading time of the website. At the same time, the size of the file will increase slightly, but due to the fact that it is cached once by the user's browser and is read from his computer when accessing other pages, as a result, the site loads much faster than a tabular one.
  2. It is much more convenient to change the design of the site pages, rendered in a CSS file. In this case, there is practically no need to edit the -code.
  3. Thanks to the possibilities of block layout, it is possible to ensure that the main content of the page goes first in the code, and only then the header, left and / or right columns. The appearance of the page will not change at all.
  4. The transparency of the block page code is visually pleasing - there are no heaps of tags, everything is very beautiful and compact.

We only talked about static pages, that is, those that, no matter how the user interacts with them, always remain unchanged, and in order for their content or design to change, the page owner needs to edit the code manually.

Dynamic pages and what they need

In addition to static, there are also dynamic pages. Most of them are on the Internet now. Information in them is loaded from external sources, such as a database or other files. The content and formatting of such pages may change depending on the user's actions. To edit dynamic sites, it is not necessary to interfere with their code - it is enough to change the content in a specially designed file or database, which, by the way, is also a file, only structured in a certain way.

To create dynamic websites, just HTML and CSS is not enough. It also uses programming languages, as well as databases and query languages ​​for them. Most often, modern dynamic sites use HTML, CSS, PHP, JavaScript, SQL in their work. The first two abbreviations are already familiar to you firsthand, SQL is used to access databases, JavaScript is a client-side language whose commands are processed by the browser and are often used to show you all sorts of beauty like curtains or smoothly opening photos, but PHP is a server-side programming language , which works, among other things, with the content of the site and makes it dynamic, we will come into contact with it today.

An example of using the include command

In the previous article, I talked about the block layout of the site and cited the simplest page as an example (document index.html and the file associated with it style.css).

Now we will split the document index.html into several files, each of which will contain its own part of the page, which will help to further separate the code, improve the structure of the template and, in fact, make the page dynamic. For this purpose, we will use the PHP language, or rather, only one of its directives - the function include(), which includes one file within another.

1. Change the permission of the file created in the article about block layout index With .html on .php to name the document index.php. File type .PHP indicates to the server that the document was written or uses inserts in the programming language of the same name.

2. In the folder with the page, create a directory blocks.

3. All supporting information (top, bottom, navigation and sidebar site) we will take out into separate files, which we will place in the folder blocks.

So, create four files in the blocks directory: header.php, navigation.php, sidebar.php And footer.php. Fill in the files with code.

4. Check the template folder structure. The files must be in the root index.php, style.css and directory blocks.

Folder structure blocks should be like this.

5. In file index.php delete the existing code and write a new one:

Block layout

Main page content

In the browser, the index.php file looks exactly the same as before, but the structure of the template has completely changed. We will talk about what happened later, and now we will answer the question about the mysterious commands of the form .

Like HTML code, PHP code also has its own start and end designation. So, you need to start a PHP insert with the command , and end with the line ?> . Between these commands, the main code is written. In our case, this is just one command - include.

Function include() inserts code from another file into the file, making it possible to store different parts of the page in different documents, thereby reliably separating them from each other.

As a result of the actions performed, we got a dynamic page index.php, parts of which are loaded from different files. Thanks to this, you can create other pages by loading auxiliary elements from the folder files in the same way. blocks.

This approach is good because if you want to change, say, the name of a menu item on a site of 20-30 pages, then in a template with a newly created structure, you will need to make changes to only one file - blocks/navigation.php, and the menu will change immediately on all pages in which it is included. If the site were static, then to change the name of one menu item, you would have to make changes to every from 20-30 pages. The difference is obvious.

 
Articles By topic:
Receiving information What is the difference between receiving information and receiving a message
Information is information about somethingThe concept and types of information, transmission and processing, search and storage of informationExpand content Collapse content Information is, definition Information is any information received and transmitted, stored
What is a landing page and how should it look like What is the name of a landing page on the Internet
Most owners of private businesses, various services and small organizations understand how important it is to conduct business online. Creating a website and maintaining a page in social networks is now part of the marketing strategy of any company. But few companies and
How to install your template on ucoz - A program that you did not know about, we are learning to connect!
How to Install a Joomla Template - Troubleshooting - 4.5 out of 5 based on 2 votes Selecting, installing and configuring a template is one of the most important steps in creating a Joomla site. In this tutorial, we'll look at how to install a template
Faibisovich - a guide to the design of electrical networks
HANDBOOK ON THE DESIGN OF ELECTRIC NETWORKS Edited by D. L. FAIBISOVICH Edition 4, revised and supplemented Reviewer V. V. Mogirev Authors : I. G. Karapetyan (pp. 3.2, 5.1, 5.3–5.8, sec. 6, sec. 7), D. L. Faibisovi