Week1 Introduction PDF
Week1 Introduction PDF
Week 1
Introduction to Web development and Tools
LAN LAN
WAN WAN
IXP
IXP IXP
WAN WAN
LAN LAN
<html>
<head>
<title>Example Web Page</title>
</head>
<body>
<p>This is a sample web page</p>
</body>
</html>
Two protocols that web applications
depend on
• HyperText Transfer Protocol (HTTP) is the protocol that web browsers
and web servers use to communicate. It sets the specifications for
HTTP requests and responses.
• Transmission Control Protocol/Internet Protocol (TCP/IP) is a suite of
protocols that let two computers communicate over a network.
Description
• HyperText Markup Language (HTML) is the language used to design the web pages of an
application.
• A static web page is an HTML document that’s stored on the web server and doesn’t
change in response to user input. Static web pages have a filename with an extension of
.htm or .html.
• When the user requests a static web page, the browser sends an HTTP request to the web
server that includes the name of the file that’s being requested.
• When the web server receives the request, it retrieves the web page and sends it back to
the browser in an HTTP response. This response includes the HTML document that’s
stored in the file that was requested.
Dynamic web pages
• A dynamic web page is a page that’s created by a program or script
that’s running on a server. This means that the page can be changed
each time it is viewed.
• The changes in the page can come from processing the form data
that the user submits or by displaying data that’s retrieved from a
database server.
HTTP request
HTTP response
PHP
Script
<head>
<title>Product Discount Calculator</title>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<main>
<h1>Product Discount Calculator</h1>
<form action="display_discount.php" method="post">
<div id="data">
<label>Product Description:</label>
<input type="text" name="product_description"><br>
<label>List Price:</label>
<input type="text" name="list_price"><br>
The HTML file (index.html) (continued)
<label>Discount Percent:</label>
<input type="text" name="discount_percent">
<span>%</span><br>
</div>
<div id="buttons">
<label> </label>
<input type="submit" value="Calculate Discount"><br>
</div>
</form>
</main>
</body>
</html>
The CSS file (main.css)
body {
font-family: Arial, Helvetica, sans-serif;
margin: 1em;
padding: 0;
}
main {
display: block;
width: 450px;
margin: 0 auto;
padding: 1.5em;
background: white;
border: 2px solid navy;
}
h1 {
color: navy;
}
label {
width: 10em;
padding-right: 1em;
float: left;
}
The CSS file (main.css) (continued)
#data input {
float: left;
width: 15em;
margin-bottom: .5em;
}
#data span {
padding-left: .25em;
}
#buttons input {
float: left;
margin-bottom: .5em;
}
br {
clear: left;
}
The PHP file (display_discount.php)
<?php
// get the data from the form
$product_description = $_POST['product_description'];
$list_price = $_POST['list_price'];
$discount_percent = $_POST['discount_percent'];
<head>
<title>Product Discount Calculator</title>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<main>
<h1>Product Discount Calculator</h1>
<label>Product Description:</label>
<span><?php echo $product_description_escaped; ?></span><br>
<label>List Price:</label>
<span><?php echo $list_price_formatted; ?></span><br>
The PHP file (display_discount.php) (continued)
<label>Standard Discount:</label>
<span><?php echo $discount_percent_formatted; ?></span><br>
<label>Discount Amount:</label>
<span><?php echo $discount_formatted; ?></span><br>
<label>Discount Price:</label>
<span><?php echo $discount_price_formatted; ?></span><br>
</main>
</body>
</html>
Notepad++ with three tabs open
Figure 1-10 How to edit a PHP file with a text editor (cont…)
How to close the current file in Notepad++
• Use the Close button in the toolbar.
Figure 1-10 How to edit a PHP file with a text editor (cont…)
The XAMPP control panel
Figure 1-11 How to start and stop Apache and MySQL on your own computer
How to start the XAMPP control panel
• Select the XAMPP Control Panel item from the Windows Start
menu or double-click on the XAMPP icon on your desktop.
About XAMPP
• XAMPP is a free, open-source web server package.
• The package consists of Apache, MySQL, and interpreters for
PHP.
• XAMPP can be easily installed.
• XAMPP is available for Windows, Linux, Solaris, and Mac OS X
systems (the X in XAMPP stands for cross-platform).
Figure 1-11 How to start and stop Apache and MySQL on your own computer (cont…)
The directories for a PHP app on a local server
xampp
htdocs (the document root directory)
guitar_store (the application root directory)
admin
catalog
styles
images
index.php
The structure for book_apps and ex_starts
xampp
htdocs
book_apps
ch01_product_discount
ch02_product_discount
ch02_future_value
ch04_product_list
ch04_product_manager
...
ex_starts
ch02_ex1
ch02_ex2
ch04_ex1
...
How to deploy a PHP application on a local server
• Copy all of the directories and files for an application to the
\xampp\htdocs directory on the server.
Figure 1-15 How to view the source code for a web page
How to view the source code for a page
in Chrome and Firefox
• Right-click the page, then select the ViewPage Source command.
Figure 1-15 How to view the source code for a web page (cont…)
NetBeans with three files in a project open
Figure 1-16 How to use NetBeans to work with projects and files
How to work with NetBeans projects
• To open a project, use the Open Project button in the toolbar.
• To start a new project, use the New Project button in the toolbar.
• To close a project, right-click on the project in the Projects tab
and select the Close command from the resulting menu.
Figure 1-16 How to use NetBeans to work with projects and files (cont…)
About NetBeans
• NetBeans is an Integrated Development Environment (IDE) for
developing PHP applications.
• NetBeans can make it easier to create, edit, and test the HTML,
CSS, and PHP files that you need for a web application.
Mac OS X note
• To enable right-clicking with Mac OS X, you can edit the system
preferences for the mouse.
Figure 1-16 How to use NetBeans to work with projects and files (cont…)
Auto-completion and error marking in NetBeans
Figure 1-17 How to use NetBeans to edit and test a PHP application
How to edit a PHP file with NetBeans
• Use normal editing techniques as you enter PHP code.
• When you see an auto-completion list, you can highlight an entry
and press the Enter key to enter it into your code or you can
double-click on it.
• If you see a red error icon at the start of a line that you have
entered, you should fix whatever errors the line contains before
you test the application.
Figure 1-17 How to use NetBeans to edit and test a PHP application (cont…)
The dialog box for starting a new project
Figure 1-18 How to use NetBeans to import and configure a PHP project
The dialog box for configuring a project
Figure 1-18 How to use NetBeans to import and configure a PHP project
(cont…)
How to check the run configuration for a project
• Right-click on a project in the Projects tab and select the
Properties command.
• Then, click on Run Configuration in the Categories list and check
the Project URL.
Figure 1-18 How to use NetBeans to import and configure a PHP project
(cont…)
References
• Chapter 1 of Murach, J. and Harris, R. (2017). Murach’s PHP
and MySQL. 3rd ed. USA: Mike Murach & Association