PHP101 - What is PHP?

From mi-linux
Revision as of 10:02, 20 September 2023 by Alix (talk | contribs) (→‎Let's get started!)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Main Page >> Web Application Development >> Workbook >> What is PHP

Introduction

"PHP (PHP: Hypertext Preprocessor) is a reflective programming language originally designed for producing dynamic Web pages. PHP is used mainly in server-side application software, but can be used from a command line interface or in standalone graphical applications." Wikipedia

Some of the features of PHP :

Open Source – the source code is generally available to the public, who may update or modify it. Generally, the production of the code is a collaborative venture between programmers, and is a response to proprietary code produced by corporations such as Microsoft. The software is, therefore, FREE.

Server-Side – in a client-server model, such as the Web, the scripts are run on the Web Server and not the client’s PC. This is in contrast to JavaScript, which is executed on the client’s PC.

Dynamic Web Pages – are pages which can change every time a client accesses them (changes may be due to the client’s location, the time of day, profile of the viewer etc). In this case Dynamic Web Pages means HTML extensions that will enable a Web page to react to user input without sending requests to the Web server.

Let's get started!

1. Open your preferred text editor (see here for more information) and create the following text file exactly (you should NOT copy and paste this - you should retype it so that you become familiar with writing PHP) - make sure you include every symbol from the box below:

<?php
   echo 'Hello World';
?>

2. Save this file somewhere in your public_html directory (see (S)FTP notes)

3. Open your favourite browser (Firefox, Opera, etc.) and navigate to the following URL

http://mi-linux.wlv.ac.uk/~YOURSTUDENTNUMBER/test1.php

(replace YOURSTUDENTNUMBER with your student number, but make sure you keep the ~ symbol)

4. You should see "Hello World" in your browser window

5. Congratulations - you have just written and executed your first PHP program.

That was easy - what's next?

Whilst the commands you just entered were relatively straightforward, PHP does not get very much more complicated than this. The process of creating and running PHP programs is exactly the same:

1. create a PHP text file

2. add PHP commands to it

3. point your browser at it

That's it!

So how does it actually work? - You need to know this for your assessments

When you point your browser at your PHP file, a number of things happen:

1. The web server application (Apache on mi-linux.wlv.ac.uk in this instance) receives the incoming request for a file called "test1.php" from the "public_html" directory of user "YOURSTUDENTNUMBER"

2. The PHP application has been installed on mi-linux.wlv.ac.uk and Apache has been configured to recognise requests for PHP files.

3. Instead of just sending you straight back the PHP file, Apache retrieves the file and "sends it" to PHP for processing.

4. PHP (the program) "runs" your PHP file, and returns back to Apache the results from running your file - in the case above, the result was to print out or "echo" the string "Hello World"

5. Apache then sends you (the client) the resulting output from the PHP execution of your PHP file.

Easy, no? Well don't worry, by the end of the module, you will be able to recite this without thinking! Trust me!

Ready to move on?

If you don't understand this page and the exercise you've done, or couldn't get it working - STAY HERE and ask for help. DO NOT MOVE ON until this makes sense to you - there is no point continuing past this point until you're happy with this page.

When you're happy you understand what you've done here, take a look at PHP102 - A Basic Page