Content of the lesson:
In the previous lessons aimed to the creation of web pages using HTML and CSS you saw how to create a static website. A simple text file was created (usually using the .htm or .html extension) and a CSS file to define the appearance of the website was added. If you open such a file in your web browser it reads it line after line and displays it. This way is fully static - you see exactly the same what is written inside the HTML file. No information can be changed automatically. All these pages are being called static (we do not consider technologies like Javascript or dynamic styles of CSS).
Internet if full of www pages nowadays and some of these pages display information which are requested by a person or which are being processed later. Consider a few examples:
There are several technologies which allow you to get dynamic www pages:
You should remember the basic technologies to create World Wide Web.
The connection of these three technologies does not allow much nowadays. It allows you to create electronic documents in HTML which are linked to each other using hypertext (a system of links). To have a web which is interactive and to have the possibility to generate HTML files on the fly (to create pages which change throughout time), you should realize that every HTML page is a file saved on a hard drive of WWW server and it has its unique URL. You can simply create an executable file using any URL. This idea formed CGI (Common Gateway Interface) and first forms appeared (http://cs.wikipedia.org/wiki/Common_Gateway_Interface).
A user can input information and send it to a server which runs a CGI-script (program written using a programming language). This script processes the data and returns a HTML page which is displayed to user. To write CGI scripts you can use languages like PERL, C++, JAVA etc.
At the beginning these technologies were expanded (due to slow transfer speeds) using JAVA or JavaScript which are run on the client side and reduce the size of transferred data. Using the JavaScript is limited by browsers because each browser uses another implementation of this language. Java also demands quite high performance but has one great advantage - you do not have to worry about the type of operating system which runs on the client computer.
PHP works on the principle which was described in the previous part. PHP is a programming language to create scripts which is mostly used for creating dynamic internet pages. PHP scripts are usually processed at the server site and the result is transferred to a client. A user requests a page from a server, this server processes the request (runs the PHP script and gets a result - HTML code in most cases) and transfers the result to the user. The final HTML file is not a static text file but it is the result of the PHP script (result of a program).
Simple example of a PHP script test.php:
<?php
print("Hello, this text was written by PHP!");
?>
If you run the previous script (you place it on www server and request it), you will see a HTML page which will contain only the string "Ahoj, já jsem text vypsaný programem v jazyku PHP!". You can see the similarity to Pascal which uses a similar command to write to console - writeln('Ahoj, já jsem text vypsaný programem v jazyku PHP!');. The mark <?php means the beginning of a PHP script (a mark for the server to consider the following text as a program). The mark ?> means the end of a PHP script. This simple script contains only one print command, which gets one parameter and writes it to a browser.
Find a virtual web server in the Internet which can be used in your computer to be able to run PHP scripts.
You might have found WampServer which can create a virtual server on your computer to launch PHP scripts and test your web applications. Wampserver can be downloaded for free in the bottom part of this page (you can choose 32-bit or 64-bit version). You do not have to change anything while installing, the program automatically places its working directory to C:\Wamp\. You can find a sub-directory www where you will place all your PHP scripts. It is a good habit to create additional sub-directories to better orientate in your files.
When you launch WampServer, you will see a small icon in tray - this icon is red at first and then changes to orange and to green if everything was done successfully. In case that it remains red or orange you should solve a possible error. You have to close Skype while using WampServer because these programs use the same ports. Another conflict service is IIS (Internet Information Service) which is a part of Professional and higher versions of Windows - you can uninstall or deactivate this service. In case you want to use WampServer and IIS together, you should open the configuration file C:\Wamp\bin\apache\Apache2.2.17\conf\httpd.conf and change the port after command Listen to 8080.
You will see this screen when you open your browser and enter the address localhost (in case you changed your port you have to use localhost:8080). You can see the headline Your Projects in the bottom part, all your PHP files will be listed here and can be run as files on a server.
WampServer also allows you to use an internal database which can be controlled by the link phpmyadmin in the bottom part.