You are on page 1of 30

SOFT7008

Server Side Programming


PHP-01
• HTML vs. PHP

• HTML

• Basics

• Images

• Tables

• Lists

• PHP

• embedding PHP code

• Testing output of PHP

What is PHP?

• PHP doesn't really stand for anything

• PHP is a programming language for programs that are run on web servers

2
HTTP request

HTTP Request

HTTP Response

• A web server sends back HTML files in response to HTTP requests

HTTP request

HTTP Request

HTTP Response
HTML

• A web server sends back HTML files in response to HTTP requests

HTTP request

Partypage.html

<html>
<head>
<title>Party Page</title>
</head>
<body>
Fun. Fun. Fun.
</body>
</html>

• A web server sends back HTML files in response to HTTP requests

HTTP request

Partypage.html
Fun. Fun. Fun.

<html>
<head>
<title>Party Page</title>
</head>
<body>
Fun. Fun. Fun.
</body>
</html>

• A web server sends back HTML files in response to HTTP requests

• The browser using the HTML file to construct the desired web page
Client Side Programming

HTTP Request

HTTP Response

• A client side program (usually JavaScript) can be included with the HTML file

Client Side Programming

HTTP Request

HTTP Response JS

HTML

• A client side program (usually JavaScript) can be included with the HTML file

Client Side Programming

HTTP Request

JS

HTTP Response JS

HTML

• A client side program (usually JavaScript) can be included with the HTML file

• The client side code is run by the browser


Server Side Programming
HTTP Request PHP

Top 10 Offers HTML

HTML

HTTP Response

• A server side program can be included with the HTML file

Server Side Programming


HTTP Request PHP

Top 10 Offers HTML

HTML

HTTP Response

• A server side program can be included with the HTML file

• This code is run by the server. Client just sees regular HTML

Server Side Programming


HTTP Request PHP

Top 10 Offers HTML

HTML

HTTP Response

• A server side program can be included with the HTML file

• This code is run by the server. Client just sees regular HTML

• Think of it as an add-on to the server

Server Side Programming


HTTP Request PHP

Top 10 Offers HTML

HTML

HTTP Response

• A server side program can be included with the HTML file

• This code is run by the server. Client just sees regular HTML

• Think of it as an add-on to the server

MySQL
• The PHP engine may also get information from a database
PHP Outputs HTML
HTTP Request

Top 10 Offers

HTML

HTTP Response

• The user's browser just displays the HTML

• All of the processing is done by the server

• The server just sends the correct HTML to the browser

MySQL
• We must be mindful that we are writing a web page
HTML

• To work with PHP we need to know the basics of HTML so that we can
code HTML files

• HTML uses markup tags to mark the beginning and end of different
sections

• Sections may be nested inside other sections


Example 01
<! DOCTYPE HTML>
<table>

</tr>

<html lang = "en">


<caption>Team Member Ages</caption>

<tr>

<head>
<tr>

<td>Harry</td>

<meta charset="UTF-8">
<th>Name</th>

<td>31</td>

<title>SOFT7008 Example 01</title>


<th>Age</th>

</tr>

</head>
</tr>

<tr>

<body>
<tr>

<td>Jane</td>

<h1>Hello world</h1>
<td>Tom</td>

<td>25</td>

This is a sample HTML page.<br/>


<td>32</td>

</tr>

<img src="photo1.jpg" alt="photo of me" </tr>

</table>

width="200" height="200" />


<tr>

</body>

<br/>
<td>Dick</td>

</html>
<td>22</td>

Viewing a HTML file

• We can see how a HTML file will look on the web by opening it in a
browser

• However that displays it locally

• It might work differently when viewed on the web. Many web servers, for
example, use case sensitive file names
Viewing a HTML file
HTTP Request

HTTP Response

• So it's better to view the HTML file via a web server

• When using the XAMP web server we place the pages in the htdocs folder

• In the browser we preface the file name with localhost

• http://localhost/example01.html
Viewing a HTML file

• People used to coding HTML typically view


the HTML file I the browser locally

• But when we working with PHP we must


always view the file via the web server
HTML Lists

• HTML supports several kinds of list

• Bread
1. Bread

• Jam
2. Jam

• Butter
3. Butter

• Milk 4. Milk
Unordered List

• An unordered list uses bullet points to identify the list items

• Bread
1. Bread

• Jam
2. Jam

• Butter
3. Butter

• Milk 4. Milk
Unordered List

• An unordered list uses bullet points to identify the list items

<ul>

<li>Bread</li>
• Bread

<li>Jam</li> • Jam

<li>Butter</li> • Butter

<li>Milk</li>
• Milk
</ul>
Unordered List

• An ordered list uses numbers to identify the list items

<ol>
1. Bread

<li>Bread</li>

<li>Jam</li> 2. Jam

<li>Butter</li> 3. Butter

<li>Milk</li>
4. Milk
</ol>
no numbers in the HTML
<ol> Nested Lists
<li>Pizza • Lists may be nested

<ul>
• Is is very important to put the closing tags in the right place
<li>Hawaiian</li>

<li>Four Cheese</li> 1. Pizza

</ul> • Hawaiian

</li> • Four Cheese

<li>Jam</li> 2. Jam

<li>Butter</li>
3. Butter

<li>Milk</li>
4. Milk
</ol>
My favourite foods are

<ul>
My Top 5 hobbies are

<li>Pizza
<ol>

<ol>
<li>Running</li>

<li>Hawaiian</li>
<li>Swimming</li>

<li>Chorizo</li>
<li>Jumping</li>

</ol>
<li>Dancing</li>

</li>
<li>Sleeping</li>

<li>Chips</li>

</ol>
<li>Apples</li>

</ul>

</ol>
1. France

• Paris

a. Champs Élysées

b. Rue des Irlandais

c. Place de la Concorde

• Rennes

2. UK
a. Rue de Soifs
Nested List Exercise
• London

• Manchester

3. Germany

• Munich

• Berlin

• Dusseldorf
Adding PHP to a HTML file
<body>

• PHP code can be added to a HTML Hello


file

<?php
• Code between the <?php > tags is
run by the server when the page is
echo "World"
served up

>
• The file is saved with .php extension
</body>
<! DOCTYPE HTML>
<html lang = "en">
<head>
<meta charset="UTF-8">
<title>SOFT7008 Example 04</title>
</head>
<body>
<h1>Hello again world</h1>
This is a sample PHP page. But remember it's still a HTML page too.<br/>
<img src="img/cit.png" alt="CIT logo" width="50" height="50" />
<br/>
Today is
<?php
echo date('l, F dS Y.');
<h1>Hello again world</h1>
This is a sample PHP page. But remember it's still a HTML page too.<br/>
<img src="img/cit.png" alt="CIT logo" width="50" height="50" />
<br/>
Today is
<?php
echo date('l, F dS Y.');
?>
<br/>
<br/>
Seven multiplied by six is
<?php
echo(7*6);
?>

You might also like