Php tutorial

<< Prev
Next >>

Introduction

Php (Hypertext Preprocessor) is a server-side scripting language that help people to make web pages interactive.


Unlike the html pages that run in the browser (html pages can be built and browser tested directly on the PC without any other program), the php pages run on the server and only the resulting page after preprocessing is displayed in the browser.
So, to test a php page, we need a web server.


In order not to install the Apache web server and the PHP preprocessor separately, there is the free XAMPP application installed in Windows that automatically configures both the Apache web server and the PHP preprocessor, the MySql database, the graphical database management interface: phpMyAdmin , web server for java, Tomcat and others.
First we download the XAMPP.exe application and install it.
Follow the installation instructions:


Xampp

Click Next


Xampp

Select installation packages (it's good to check them all) and click Next


Xampp

Select the installation directory (it is good to be C: \ xampp) and click Next


Xampp

Click Finish and the installation is ready.
In the xampp directory, there is an executable file: xampp-control.exe.


Xampp

Double-click on it and it opens:


Xampp

From here, we can start and stop web servers and MySql database server. We will start the Apache web server:


Xampp

The directory from which the Apache server serves the web pages is called htdocs and is found in the xampp directory


Xampp

In the htdocs directory, there must be a file named index.html (or index.php) that is the home page of any website


Xampp

Apache web server is turned on, we will open a browser (Chrome, Firefox, IE) and we will type: http: // localhost (or http://127.0.0.1, which is the loopback IP address).
If the Apache web server has been installed correctly, the index.html (found in C: / xampp / htdocs) will open in the browser.


Xampp

To test now if the Apache web server can also serve PHP pages, we will open Notpad and create a file called phpinfo.php, as in the following figure:


Xampp

Put this file into the htdocs directory (where the Apache web server serves web pages).


Xampp

Open a browser (Chrome, Firefox, IE) and type: http: //localhost/phpinfo.php. If the PHP preprocessor is installed correctly, a page with all the information about the installed PHP modules will appear.


Xampp

In this case everything is OK and we can start working with PHP.


Php scripts

A PHP page may contain HTML code and PHP scripts. A PHP script to be recognized and executed by the preprocessor (in the web server) will be between the tags: <?php and ?>.


Adding 2 numbers using PHP script

Sum

Saves the file as sum.php and puts it in the htdocs directory. Open browser and access:


Add

Enter 2 numbers and click the Sum button:


Add
<< Prev
Next >>

Visit my websites:

https://www.jwebsaints.com
https://www.jwebplants.com