Dynamic pages in PHP. PHP. Dynamic page creation Index php creation

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 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 received 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.

Precautions must be taken. Because the resource can turn out to be extremely dynamic. That and look, bite!

PHP and HTML

Now these two disciplines are almost connected together. Their tandem is the basis on which the "life" of most of the Internet is built. Of course, other server-side languages ​​(Perl, ASP.NET) are also used in conjunction with html. But their prevalence on the World Wide Web, compared to PHP, is purely episodic.

According to statistics, the architecture of most resources on the Internet is built on the basis of php and html.


For many beginners, the relationship between these technologies seems incomprehensible. On the one hand, static html , which is interpreted by browsers on the client side. On the other hand, it is a programming language that is processed on the server. Therefore, before writing a site in php from scratch, we will give a simple example of the interaction of these two technologies:

  • Let's create a new file with php extension;
  • Let's put the following code there:

Untitled web page What time is it now?

  • Let's save the file on the local server and open it in the browser. Then click on the right mouse button and context menu choose the item " View html page».

As you can see in the screenshot, the lineis not displayed in the html code of the page. Both in the browser and in the code, only the returned date and time are visible. This means that the script was processed on the server side. Therefore, creating a site in php is fundamentally different from writing simple html pages.

Dynamic site

There are two main types of websites today:

  • Static - created only on the basis of html . Such sites do not change their content in response to user actions. Of course, a static resource can respond to events and user actions. But the client-side implementation of page dynamism has a narrow scope, limited by the capabilities of Java Script.

The Java Script code runs in the browser on the client side.

  • Dynamic - capable of changing their state and content - html pages of dynamic sites are formed on the fly at the time of code execution in response to a user request sent by him from the browser to the server. Most often, page generation on the server side occurs using code written in php .

A dynamic php site consists of the following files:

  • index.php is the main project file;
  • Templates - include the structure of a particular part of the page ( caps, basement, main body);
  • CSS files - store all the style descriptions of the resource.

In addition, the site project may consist of files that store the code of php functions and methods. And also include a database.

In most CMS, the content source for filling pages dynamically generated on the server side is the database. The most commonly used database is MySQL.

How to write a website in PHP

To understand how a site is created in php, let's look at a practical example. Of course, much of it is simplified, but the entire mechanism of work and the stages of creation are preserved.

I have an html site with the following structure and design:

His code:

PHP site example

A cap

Content

style.css file code:

Header ( margin-left:auto; margin-right:auto; margin-bottom:10px; width:1000px; height:100px; border:1px solid #000000; background: #009966; background-image: url(img/1. gif); ) .pages ( margin-left:auto; margin-right:auto; width:1000px; ) .content ( margin-right:10px; width:806px; height:450px; border:1px solid #000000; background: #999999; float:left; ) .sidebar ( width:180px; height:450px; border:1px solid #000000; background: #FF9900; float:left; ) .foot ( clear:both; ) .footer ( margin-top :10px; margin-left:auto; margin-right:auto; width:1000px; height:50px; border:1px solid #000000; background: #333399; )

Before you write a site in php to the end, all the html code needs to be spread over several files:

  • Header.php will include all the code from the beginning to the end of the "header" layer;
  • In footer.php - layer "foot" and "footer";
  • In content.php - all the code left in the middle.

Now we create the main index.php page, which will contain file calls containing the code of the necessary design elements. In total, there were only 3 lines of the script in the main file:

And if you look at the html code of the page in the browser, you will see the code of the original source:

Of course, this option is only suitable for generating the main page of the site. But if the sidebar code is removed in a separate file, then the template can also be used to generate the internal pages of the site.

The detour way

But such a site development requires effort, the availability of a specialized software and knowledge. Therefore, I would like to find an easier option. Then you should use the PHP site builder.

They are a specific set of templates with an extended range of settings. Because of what they are very similar to conventional CMS. Of course, no one guarantees the high uniqueness of the design of the future site, and in the future there may be problems with transferring and adapting the resource to another hosting site or platform. Here are some proven options for such online services.

Hello! Now we will try to implement the simplest registration on the site using PHP + MySQL. To do this, Apache must be installed on your computer. How our script works is shown below.

1. Let's start by creating the users table in the database. It will contain user data (login and password). Let's go to phpmyadmin (if you create a database on your PC http://localhost/phpmyadmin/). Create a table users, it will have 3 fields.

I create it in mysql database, you can create it in another database. Next, set the values, as in the figure:

2. A connection to this table is required. Let's create a file bd.php. Its content:

$db = mysql_connect("your MySQL server","login to this server","password to this server");
mysql_select_db ("name of the database to connect to", $db);
?>

In my case it looks like this:

$db = mysql_connect("localhost","user","1234");
mysql_select_db("mysql",$db);
?>

We save bd.php.
Great! We have a table in the database, a connection to it. Now you can start creating a page where users will leave their data.

3. Create a reg.php file with content (all comments inside):



Registration


Registration
















4. Create a file, which will enter data into the database and save the user. save_user.php(comments inside):



{
}
//if the login and password are entered, then we process them so that tags and scripts do not work, you never know what people can enter


// remove extra spaces
$login = trim($login);
$password = trim($password);
// connect to the database
// check for the existence of a user with the same login
$result = mysql_query("SELECT id FROM users WHERE login="$login"",$db);
if (!empty($myrow["id"])) (
exit("Sorry, the username you entered is already registered. Please enter another username.");
}
// if there is none, then save the data
$result2 = mysql_query ("INSERT INTO users (login,password) VALUES("$login","$password")");
// Check if there are errors
if ($result2=="TRUE")
{
echo "You have successfully registered! Now you can enter the site. Main page";
}
else(
echo "Error! You are not logged in.";
}
?>

5. Now our users can register! Next, you need to make a "door" to enter the site for already registered users. index.php(comments inside):

// the whole procedure works on sessions. It is in it that the user's data is stored while he is on the site. It is very important to launch them at the very beginning of the page!!!
session_start();
?>


Main page


Main page











Register



// Check if the login and user id variables are empty
if (empty($_SESSION["login"]) or empty($_SESSION["id"]))
{
// If empty, we don't display the link
echo "You are logged in as a guest
This link is only available to registered users";
}
else
{

In file index.php we will display a link that will be open only to registered users. This is the whole point of the script - to restrict access to any data.

6. There is a file with verification of the entered login and password. testreg.php (comments inside):

session_start();// the whole procedure works on sessions. It is in it that the user's data is stored while he is on the site. It is very important to launch them at the very beginning of the page!!!
if (isset($_POST["login"])) ( $login = $_POST["login"]; if ($login == "") ( unset($login);) ) //put the login entered by the user into the $login variable, if it is empty, then we destroy the variable
if (isset($_POST["password"])) ( $password=$_POST["password"]; if ($password =="") ( unset($password);) )
//put the password entered by the user into the $password variable, if it is empty, then destroy the variable
if (empty($login) or empty($password)) //if the user has not entered a login or password, then we issue an error and stop the script
{
exit("You did not enter all the information, go back and fill in all the fields!");
}
//if the login and password are entered, then we process them so that tags and scripts do not work, you never know what people can enter
$login = stripslashes($login);
$login = htmlspecialchars($login);
$password = stripslashes($password);
$password = htmlspecialchars($password);
// remove extra spaces
$login = trim($login);
$password = trim($password);
// connect to the database
include("bd.php");// the bd.php file should be in the same folder as everyone else, if it's not then just change the path

$result = mysql_query("SELECT * FROM users WHERE login="$login"",$db); //retrieve all data about the user with the entered login from the database
$myrow = mysql_fetch_array($result);
if (empty($myrow["password"]))
{
//if the user with the entered login does not exist
}
else(
//if exists, check passwords
if ($myrow["password"]==$password) (
//if the passwords match, then we start the session for the user! You can congratulate him, he entered!
$_SESSION["login"]=$myrow["login"];
$_SESSION["id"]=$myrow["id"];//this data is very often used, so the logged in user will "carry" them
echo "You have successfully logged into the site! Main page";
}
else(
//if passwords don't match

Exit("Sorry, the login or password you entered is incorrect.");
}
}
?>

OK it's all over Now! Maybe the lesson is boring, but very useful. Only the idea of ​​registration is shown here, then you can improve it: add protection, design, data fields, upload avatars, log out of your account (for this, simply destroy the variables from the session with the function unset) and so on. Good luck!

Checked everything, it works fine!

Many readers in any book about computers will skim through everything that is not of immediate interest and go on to what they really want know. Personally, I do exactly that. However, there is nothing to worry about - rarely there are technical books that need to be read from cover to cover. Or maybe you did exactly that - skipped the eight initial chapters and took up this chapter because it had the most interesting title? And who wants to waste time on details when another project is on fire at work?

Luckily, this haste won't stop you from getting the hang of the second part of the book, which is about using PHP to build websites and interact with the Web. In this chapter, you will learn how to easily modify the content of web pages and navigate the Web using links and various standard functions. The next chapter will complement the material presented - it discusses in detail the means of user interaction in HTML forms. Chapter 11 describes the organization of the interface with databases. The rest of the chapters in Part 2 cover the non-trivial aspects of web programming in PHP.

However, it should be remembered that the material of part 1 absolutely essential for normal knowledge of PHP. It is assumed that you have read the first part, so the examples will use many of the concepts discussed earlier. So, if you have skimmed through part of the book, you will have to go back to previous chapters from time to time and catch up.

Simple Links

<а href = "date.php">

$link = "date.php";

print"<а href = \"$link\">View today's date
\n"

You might be wondering why there is a backslash (\) before quotes (") in the link code? This is because quotes are special characters in PHP and are used as string delimiters. Therefore, quotes are literal strings in strings. must be shielded.

If the need to escape quotes annoys you, just turn on the magic_quotes_gpc mode in your php.ini file. The result is all apostrophes, quotes, backslashes, and null characters. are automatically escaped in the text!

Let's develop the given example. To quickly display a list of links in the browser, you can use an array:

// Create an array of sections

$contents - array("tutorials", "articles", "scripts", "contact");

// Loop through and output each element of the array sequentially

for ($i = 0; $i< sizeof($contents; $i++)

print " ".$contents[$i]."
\n";

// - special designation of marker point endfor;

File components (templates)

We've come to one of my favorite PHP features. A template (as applied to web programming) is a part of a web document that you are going to use in several pages. Templates, like PHP functions, save you the hassle of copying/pasting fragments of page content and program code. As the scale of the site increases, the importance of templates increases, as they allow you to easily and quickly make modifications at the level of the entire site. This section will describe some of the possibilities that open up when using the simplest templates.

Typically, common pieces of content/code (i.e. templates) are stored in separate files. When building a web document, you simply "include" these files in the appropriate places on the page. PHP has two functions for this: include() and require().

include() and require()

One of the most outstanding aspects of PHP is the ability to build templates and programming libraries and then insert them into new scripts. The use of libraries saves the time and effort of using common functionality across different websites. Readers with

programming experience in other languages ​​(eg C, C++ or Java), familiarity with the concept of function libraries and their use in programs to extend functionality.

Including one or more files in a script is done using the standard PHP require() and include() functions. As will be shown in the next section, each of these functions is used in a specific situation.

Functions

PHP has four functions for including files in PHP scripts:

  • include();
  • include_once();
  • require();
  • require_once().

Despite the similarity of names, these functions perform different tasks.

The include() function includes the contents of a file in a script. The syntax of the include() function is:

include (file file]

The include() function has one interesting feature - it can be conditionally executed. For example, if a function call is included in an if statement block. then the file is included in the program only if the condition i f is true. If the includeO function is used in a conditional command, then it must be enclosed in curly braces or alternative delimiters. Compare the syntax differences in listings 9.1 and 9.2.

Listing 9.1. Incorrect use of include()

if (some_conditional)

include("text91a.txt"); else

include("text91b.txt");

Listing 9.2. Proper use of include()

if (some_conditional) :

include("text91a.txt");

include("text91b.txt");

All PHP code in the include file Necessarily is in PHP tags. Don't assume that simply storing a PHP command in a file will ensure that it is processed correctly:

Instead, you must enclose the command in the appropriate tags, as shown in the following example:

print "this is an invalid include file";

The include_once() function does the same as include(), with one exception: it checks to see if the file has already been included before it is included in the program. If the file has already been included, the include_once() call is ignored, and if not, the file is included by default. In all other respects, include_once() is no different from include(). The syntax of the include_once() function is:

include_once (file file)

In general, the require() function is similar to include() -- it also includes the template in the file containing the call to require(). The syntax of the require() function is:

require (file file)

However, there is one important difference between the require() and include() functions. The file specified by the require() parameter is included in the script, regardless of the location of require() in the script. For example, if you call requirere() in an if block with a false condition, the file will still be included in the script!

In many situations, it is convenient to create a file with variables and other information that is used across the site, and then include it as needed. Although the name of this file is arbitrary, I usually call it init.tpl (short for "initializaion.template"). Listing 9.3 shows what a very simple init.tpl file looks like. In Listing 9-4, the contents of init.tpl are included in the script with the require() command.

Listing 9.3. Example initialization file

$site_title = "PHP Recipes";!}

$contact_email = " [email protected]";

$contact_name = "WJ Gilmore";

Listing 9.4. Using the init.tpl file

<? print $site_title; ?>

\"mai1 to:$contact_email\">$contact_name."; ?>

Passing a URL when calling require() is only allowed if the "URL fopen wrappers" mode is enabled (this mode is enabled by default).

As the size of the site increases, it may happen that some files are included in the script more than once. Sometimes this doesn't cause problems, but in some cases re-enabling the file resets the changed variables. If functions are defined in an include file, name conflicts can occur. With that said, we come to the next function, require_once().

The require_once() function ensures that the file will only be included in the script once. After a call to requi re_onse(), all further attempts to include the same file are ignored. The syntax of the require_onse() function is:

You'll likely use the file include functionality more often as your web applications grow in size. These functions are often used in the examples in this book to reduce code redundancy. The first examples are discussed in the next section on the principles of building basic templates.

Building Components

When defining the structure of a typical web page, I usually break it down into three parts: a header, body, and footer. Typically, most well-organized websites will have a heading that doesn't change much; the main part displays the requested content of the site, so it changes often; Finally, the footer contains copyright information and navigation links. The footer, like the header, usually remains unchanged. Don't get me wrong - I'm not trying to stifle your creativity at all. I've seen a lot of great sites that didn't follow these principles. I'm just trying to come up with a general structure that can serve as a starting point for further work.

header

A header file (like the one in Listing 9.5) is present in almost every one of my PHP-enabled websites. This file contains

site-wide information, such as the title, contact information, and certain components of the HTML page code.

Listing 9.5. Header file example

// File: header.tpl

// Purpose: Header file for the PhpRecipes site.

$site_name = "PHPRecipes";

$site_email=" [email protected]";

$site_path = "http://localhost/phprecipes";

<? print $site_name; ?>

// Display current date and time

print date("F d, h:i a");

It is quite common for visitors to restrict access to include files, especially if the files contain sensitive information (such as passwords). In Apache, you can prevent certain files from being viewed by editing the http.conf or htaccess files. The following example shows how to disable viewing of all .tpl files:

order allow,deny

Allow from 127.0.0.1

PHP and site security issues are covered in detail in Chapter 16.

Running title

Header (footer) is usually called the information located at the bottom of the pages of the site - contact details, links and copyright information. This information can be placed in a separate file and included as a template in the same way as a header. Let's say that with the advent of the new year, you needed to change the copyright information and bring it to the form "Copyright © 2000-2001". There are two ways: spend Christmas Eve feverishly editing hundreds of static pages or use a template like the one in Listing 9.6. One simple change and you can be back to holiday chores.

Listing 9.6. Footer file example (footer.tpl)

contact |

your privacy

Note the use of the $site_email global variable in the footer file. The value of this variable is page-wide, and we assume that the header.tpl and footer.tpl files will be included in the same final page. Also note the presence of the $site_path in the Privacy link. I always include the full paths to all links in my templates -- if the link's URL consisted of the single name privacy.php, then the footer file would be hard-coded to a specific directory.

Main part

The content of the header and footer is included in the main part of the page. In essence, it is the main part that contains the information of interest to site visitors. The header looks spectacular, the footer contains useful information, but it is for the main part of the page that users return to the site again and again. Although I can't provide any advice on the specific page structure, templates like the one in Listing 9-7 make page administration much easier.

Listing 9.7. Example of the main body of the page (index_body.tpl)

/tutorials.php">tutorials

articles

scripts

contact

Welcome to PHPRecipes. the starting place for PHP scripts, tutorials,

and information about gourmet cooking!

Putting it All Together: Header, Footer, and Body

Perhaps my mood is best expressed by Colonel "Hannibal" Smith (George Peppard) from the famous A-Team series: "I love it when everything falls into place." I experience something similar when disparate templates are combined to form a complete web document. By combining three document sections: header.tpl, index_body.tpl, and footer.tpl, you can quickly build a simple page like the one in Listing 9-8.

Listing 9.8. Building the index.php page by including several files

// File: index.php

// Destination: PHPRecipes homepage

// Display title

include("header.tpl");

// Output main body

include("index_body.tpl");

// Output footer

include("footer.tpl");

Well, how? Three simple commands - and you have a finished page in front of you. The text of the summary page is shown in Listing 9.9.

Listing 9.9. The HTML page built in Listing 9-8 (index.php)

PHPRecipes

August 23, 03:17 pm

tutorials

articles

scripts

contact

Welcome to PHPRecipes, the starting place for PHP scripts, tutorials,

and gourmet cooking tips and recipes!

Copyright 2000 PHPRecipes. All rights reserved.

contact |

your privacy

On fig. Figure 9-1 shows how the resulting page looks in the browser. Although I usually don't use table borders, this time I've included them so that the three parts of the page stand out more clearly in the figure.

Rice. 9.1. The appearance of the page built in listing 9.8

Template Optimization

In the second (in my opinion, more preferable) variant, the templates are made in the form of functions located in a separate file. This provides additional structuring for your templates. I call this file the initialization file and store other useful information in it. Because we've already looked at the relatively long header and footer examples, Listings 9-10 and 9-11 have been shortened slightly to illustrate the new idea.

Listing 9.10. Optimized site template (site_init.tpl)

// File: site_init.tpl

// Purpose: PhpRecipes initialization file

$site_name = "PHPRecipes";

$site_email = " [email protected]";

$site_path = "http://localhost/phprecipes/";

function show_header($site_name) (

<? print $site_name: ?>

This is the header

function show footer()

This is the footer

Listing 9.11. Applying an initialization file

// Include initialization file

include("site_init.tpl");

// Display title

show header($site_name);

// Body content This is some body information

// Show footer Show_footer();

Project: page generator

While most of the websites I've built have generated the main content of the pages based on information read from the database, there will always be a few pages that barely change. In particular, they can display information about the development team, contact information, advertisements, etc. I usually store this "static" information in a separate folder and use a PHP script to load it when requested. Of course, you have a question - if this is static information, what is the PHP script for? Why not load normal HTML pages? The advantage of PHP is that you can use templates and insert static snippets as needed.

<а href = "/static.php?content=$content">Static Page Name

Let's start by creating static pages. For simplicity, I will limit myself to three pages containing information about the site (Listing 9.12), advertising (Listing 9.13), and contact information (Listing 9.14).

Listing 9.12. Site information (about.html)

About PHPRecipes

What programmer doesn't mix all night programming with gourmet cookies. Here at PHPRecipes. hardly a night goes by without one of our coders mixing a little bit of HTML with a tasty plate of Portobello Mushrooms or even Fondue. So we decided to bring you the best of what we love most: PHP and food!

That "s right, readers. Tutorials, scripts, souffles and more. 0nly at PHPRecipes.

Advertising Information

Regardless of whether they come to learn the latest PHP techniques or for brushing up on how

to bake chicken, you can bet our readers are decision makers. They are the Industry

professionals who make decisions about what their company purchases.

For advertising information, contact

">[email protected].

Listing 9.14. Contact details (contact.html)

Contact us

Have a coding tip?

Know the perfect topping for candied yams?

Let us know! Contact the team at [email protected].

Let's move on to building the static.php page, which displays the requested static information. This file (see Listing 9-15) includes our site's page components and the site_init.tpl initialization file.

Listing 9.15. General output of static pages (static.php)

// File: static.php

// Purpose: Display requested static pages.

// WARNING: it is assumed that the file "site_init.tpl" and all

// static files are in the same directory.

// Load functions and variables include("site_init.tpl"):

// Display title show_header($site_name);

// Display requested content include("$content.html"):

// Show footer show footer();

Now everything is ready to build the main script. Just include in the page

<а href = "static.php?content=about">Static Page Name

Advertising Information

Contact us

Clicking on any of these links will load the corresponding static page embedded in static.php in the browser!

Results

In this chapter, you've learned about the primary goal that PHP was designed to solve: dynamically building web pages. The following questions were considered:

  • URL processing;
  • building dynamic content;
  • inclusion and construction of basic templates.

The chapter concludes with a page generator, a program that loads static pages into a template and makes it easy to maintain large numbers of static HTML pages.

The next chapter is about using PHP in combination with HTML forms to greatly enhance the interactivity of your site. And then - interaction with databases! You have to learn a lot of interesting things.

Last update: 1.11.2015

Now we will create a small site, which is designed to give an initial understanding of working with PHP.

To create programs in PHP, we need a text editor. The most popular program today is Notepad++.

Let's move on to the previously created directory C:\localhost , which will store all the site's documents. Let's create a text file and name it index.html. Open it in a text editor and add the following code to it:

First site in PHP

Enter your details:

Enter your name:

Enter last name:

The html code contains a form with two text fields. When the button is clicked, the form data is sent to the display.php script, as it is specified in the action attribute.

Now let's create this script that will process the data. Add to folder c:\localhost new text file. Let's rename it to display.php. By default, php program files have the extension .php. So let's add the following code to the display.php file:

First site in PHP ".$name . " " . $surname . ""; ?>

Here already in the html markup there are blotches of PHP code. Tags are used to add PHP expressions to a page, between which there are instructions in the PHP language. In the php code, we receive the form data and display it on the page.

Each individual PHP expression must end with a semicolon. In this case, we have three expressions. Two of them receive the submitted form data, for example $name = $_POST["firstname"]; .

$name is a variable that will hold some value. All variables in PHP are preceded by a $ sign. And since the form on the index.html page uses the POST method to submit, we can use the $_POST["firstname"] expression to get the value that was entered in the text field with the attribute name="firstname" . And this value gets into the $name variable.

With the echo statement, you can display any value or text that comes after the statement on the page. In this case (echo "Your name: ".$name . " " . $surname . ""), using a dot, the quoted text is concatenated with the values ​​of the $name and $surname variables and displayed on the page.

Now let's turn to the input form by going to the address http://localhost:8080:

Enter some data and click on the submit button:

So, the script worked for us display.php, which received and displayed the submitted data on the page.

 
Articles By topic:
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
Computer software User computer information software
Software or software (SW) is an integral part of a computer. Software is a logical continuation of technical means that expands the possibilities and scope of the use of computers. For the functioning of the computer, a set of software is used.