Learnit Training

2. Hello World

2.1. The Server

In This course we only work on the newly installed local server. Therefore, it is not possible to see the dynamic pages that you create from a place other than the computer on which you are creating them. This is obviously not the way it will eventually work. When you really want to publish your dynamic webpage you will need to use either a provider that supports PHP, or you need to set up your own PHP Web server that is open to the Internet.

However, this limitation is totally not a hindrance to learning to work with PHP. On the contrary, in this somewhat simplified setup, you do not have to worry about security and complicated server settings.

2.2. The Server and files

In the previous chapter, you already saw that surfing to http://localhost/ THE default XAMPP page. In the end we want Http://localhost/phpcursus to deliver our files. The question now is how we get our files in that place, or actually more: Where are the files that are shown on http://localhost/?

The answer to this question depends on your installation. In the previous chapter you installed XAMPP, and if you have not changed it has happened in the folder c:\xampp. If this is the case, the files that are on the server are listed in the c:\xampp\htdocs\folder. If you have installed the program somewhere else, you can find the files in c:\mijn\eigen\map\htdocs\. This is called the root directory .

From your experience with HTML, you probably already know that the index. HTML file will be displayed normally by default when you browse to a folder. On a PHP server, default index. PHP is executed when you browse to a folder and this file is present. So if you surf to http://localhost/ , it automatically refers to http://localhost/index.php, and in the standard case it means that the file c:\xampp\htdocs\index.php be executed.

2.3. Extensions

Use the Windows Explorer to browse to the root folder. Create a new folder Phpcursus/ on (right click > new > folder). In This folder you create a new file (right-click > new > text file). Name this file index. html. Make sure that the file extensions are not hidden (additional > Maptopties > View > Extensions for known file types):

Show extensions

If necessary, rename the file so that it does not include index. html. txt but index. HTML . Open this file in Notepad and type:

Surf to Http://localhost/phpcursus to see the result in a browser. The result is, if it went well, a blank page. But if you look in the source code of the page (image > source), you will see the exactetekst you typed in. Now rename the file to index. PHP and re-surf to http://localhost/phpcursus (or press F5 to refresh). Now you only see the text ' Hello World ', also in the source code. The PHP interpreter has been working!

Hello World

The server recognizes that it is a PHP file. This is not that difficult, because the filename ends on PHP. As a result, any PHP code That is interpreted in the file. PHP code is the text that And ?> State.

This is not exactly world-shattering, you had the same effect when index. PHP had looked like this (try this!):

Hello World

The only thing that the command Echo Does is that which stands out to write the output. But Echo is of course not all that PHP has to offer. In the next chapter we discuss a number of programming skills that make working with PHP meaningful.