Module 2 - How To Create A Simple Dynamic Web Application
Module 2 - How To Create A Simple Dynamic Web Application
Web Application
Overview
In our last module, we have seen web architecture components, and how a web server responds with static and dynamic contents.
We have also seen how web applications use the server-side scripts such as PHP that run on the server to provide rich and dynamic
web responses to the clients.
As you know, PHP is the most popular server-side scripting language for web application development. It’s free and open source. You
have already seen how to run and edit PHP applications. In this module, you will learn how to code simple PHP applications, and
develop basic PHP skills. Before starting this module, make sure you have completed the exercises of Module 1.
Learning Outcomes
By the end of this module, you should be able to:
Knowledge
Describe these PHP data types: integer, double, Boolean, and string.
Describe the code for declaring a variable and assigning a value to it.
Describe the rules for evaluating an arithmetic expression, including order of precedence and the use of parentheses
Describe the use of these built-in functions: intdiv(), number_format(), date(), isset(), is_numeric(), htmlspecialchars(),
filter_input(), include(), and require().
Describe how an XSS attack works and how to protect against this type of attack.
Describe the rules for evaluating a conditional expression, including order of precedence and the use of parentheses.
Use the built-in intdiv(), number_format(), date(), isset(), empty(), and is_numeric() functions.
Use the filter_input() function to filter input from the $_GET and $_POST arrays.
Use built-in functions like include() and require() to pass control to another page.
Assessments
Assignment 1: Dynamic Web Application Using PHP (10%)
Activity Checklist
The following is a list of ungraded activities designed to help you to be successful in the graded activities.
Show Answer
Show Answer
1. Which PHP variable stores the data of HTML’s GET method? What is the type of the variable?
Show Answer
2. What is superglobal variable and what does it mean? Give an example of superglobal variable in PHP.
Show Answer
Show Answer
1. True or false: There is absolutely no difference between single or double quotation marks to code a string in PHP.
Show Answer
2. Which PHP statement can you use to send data back to the browser?
Show Answer
$subtotal = 2.68;
$subtotal /= 2;
$subtotal--;
Show Answer
Show Answer
Give particular attention to the PHP file and notice how the data were retrieved from the form using the $_GET variable, how the
discount and discounted price were calculated, and how to apply formatting in currency and per cent amount.
1 === TRUE
Show Answer
2. A ________ joins two or more conditional expressions using the logical operators.
Show Answer
3. What is the difference between built-in functions “include” and “require” methods?
Show Answer
Notice how multiple PHP files are working together in an application, and when the user clicks on the Calculate button on the first
page, the data is submitted to the “display_results.php” file via the POST method.
Activity 2.9: How to Use the PHP Documentation
Whenever you learn a new programming language, it’s crucial to know how to access its documentation, because if you encounter a
problem that you can’t figure out based on what you already know, you can consult the documentation for more information. The best
place from where you should read the documentation is the official PHP manual page.
The official PHP manual site is the most up to date and accurate source of information for PHP programming language. So,
whenever you have any doubt on any functions or syntax of PHP, you should consult the official page.
The section “How to Use the PHP Documentation” in Chapter 2 of your textbook also describes how to use the official PHP
documentation page.
Exercise 11-1 Work with the arrays of the Task List Manager application
Each exercise provides direction to the required files. You can also download these files, including the exercise startup files, the
exercise solutions, and the book-applications.