COS30020 – Advanced Web Development
Lab 1 – Introduction and Getting Started with PHP
Reference: Chapter 1 of the “PHP Programming with MySQL” textbook.
Aims:
• To set up your user account on the Apache server
• To develop an understanding of the client-server environment and the processes we will be using
throughout the semester to load pages to the Apache server and view them through a Browser
• To create well-formed and valid Web pages and
• To create simple PHP pages using simple code blocks, script delimiters and
PHP built-in functions.
NOTE: To fully cover the learning objectives of the Unit, you are required to complete all Lab exercises. If you
do not complete the exercises in the lab, you will need to complete the exercises at home or in the following lab.
This will help you to complete the assignments for this unit.
Task 1: Set up and test your user account on Mercury (10 marks)
Step 1: Log onto the web server and set up your account.
A web account is needed to test and run your web (HTML and PHP) pages. Use Setting up your Mercury files
under the lab 1 to help you.
You will need to install PuTTY or a similar program for this.
Step 2: Connect to the web server to transfer files.
To test our Web pages, we need to first place them on the mercury server. Use Transferring files to and from
Mercury to help you.
You need to install WinSCP or a similar program (e.g. FileZilla).
Step 3: Create a folder (directory) to contain your web pages.
It is recommended that we create a folder for each web project. For instance, we should create a folder named
‘lab01’ to contain all files that we will be developing for this lab.
Note that the web server, mercury, is case sensitive, thus it is recommended that you use lower case and avoid
non-alphanumeric characters such as space when naming folders.
Using WinSCP, create a folder ‘lab01‘under ~/cos30020/www/htdocs folder in mercury.
Page 1
COS30020 – Advanced Web Development
Step 4: Create a web page for testing.
Use any text editor on your local computer (e.g. NotePad++) to create a file named myphp.php and code the
following:
<!DOCTYPE html>
<html lang="en">
<head>
<title>My First PHP webpage</title>
<meta charset="utf-8">
<meta name="description" content="Web development">
<meta name="keywords" content="HTML, CSS, JavaScript">
<meta name="author" content="your name">
</head>
<body>
<h1>Web Programming - Lab 1</h1>
<p>Can I create a .php file that do not contain any PHP scripts?</p>
<p>Yes, but this should be avoided, so that the server does not do any
unnecessary parsing and processing.</p>
</body>
</html>
Step 5: Transfer your web pages to the web server.
To be able to run your Web pages, you must place the files into ~/cos30020/www/htdocs folder on mercury or
any of its subfolders.
Using WinSCP, drag and drop the file ‘myphp.php’ from your local machine to the htdocs/lab01 folder.
For detail guide with complete screen shots, see “Transferring files to/from Mercury”.
To view the pages through http, use any Web browser and type in the following address,
http://mercury.swin.edu.au/cos30020/username/lab01/myphp.php
and the <username> is s< your 7-digit Swinburne ID >
When the authorization request dialog pops up, use your SIMS username and password to confirm access.
Notes:
• Step 1 is only done once. This is basically to set your new password.
• Steps 2 and 3 are performed every time you start a PHP development session.
• Steps 4 to 6 are performed repeatedly in sequence when creating, testing and debugging your PHP
codes.
Problems:
• For password problem, such as forgotten password or invalid account, call ITS Service Desk on
9214 5000 and inform them of your situation.
• For problems in completing steps 2 to 6 ask the tutor during your lab schedule.
Page 2
COS30020 – Advanced Web Development
Task 2: Develop a PHP web page (3 marks)
Step 1:
Create a new HTML file and add a PHP code block using standard script delimiter after the page heading as
follows:
<h1>Use of PHP built-in functions</h1>
<?php
?>
Step 2:
Now add some PHP code inside the script delimiters:
For example, use abs() built-in function which calculates absolute value of an integer and pow() function which
calculates the value of x to the power of y. Use the echo statement to print the results
(Note: It is good practice to include useful comments in your code):
<?php
/* Use of abs() and pow() built-in functions, and echo statement. */
echo "<p>Absolute value of -9 is: ", abs (-9),".</p>";
echo "<p>2 to the power of 5 is : ", pow(2,5),".</p>";
?>
Step 3:
Save the file as “functions.php”, if a file name has not been assigned yet.
Use WinSCP client to upload this file to ‘lab01’ folder that you already created in your mercury account.
Step 4:
Use any Web browser to run the PHP file.
Step 5:
Try more built-in functions, such as decbin() and bindec().
Add another PHP code block that uses a standard script delimiter and echo statements to print binary to decimal
and decimal to binary conversions, using above two functions:
<?php
/* Use of decbin() and bindec() functions. */
echo "<p>Decimal equivalent of 1101 is: ", bindec(1101),".</p>";
echo "<p>Binary equivalent of 14 is: ", decbin(14),".</p>";
?>
Page 3
COS30020 – Advanced Web Development
Task 3: Practising PHP development skills (2 marks)
• Create another web document with an <h1> element containing the text ‘Forestville Credit Union’ and
an <h2> element containing the text ‘CD Rates’.
• Add a PHP code block in the document body.
• Within the code block, use echo statements to print the following CD rate information as bullet points:
4.35% (36-Month Term CD), 3.85% (12-Month Term CD), 2.65% (6-Month Term CD).
• Use another echo statement to print a paragraph element after the unordered list that contains the text
"$1,000 minimum deposit".
• Add comments with your name and today’s date.
• Save the document as cdrates.php
Page 4