Web Development BCS IV Sem Unit I
Web Development BCS IV Sem Unit I
1) HTML
HTML Elements
An HTML element is a start tag and an end tag with content in between:
<h1>This is a Heading</h1>
HTML Attributes
<meta charset="utf-8">
<title>Page Title</title>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
HTML Document Structure
<html>
<head>
<title>Page title</title>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Note: Only the content inside the <body> section (the white area above) is displayed in a
browser.
HTML Headings
<h1> defines the most important heading. <h6> defines the least important heading:
Example
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
HTML Paragraphs
Example
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
HTML Links
HTML Images
The source file (src), alternative text (alt), width, and height are provided as attributes:
Example
<img src="img_w3schools.jpg" alt="W3Schools" style="width:120px;height:150px"
HTML Buttons
Example
<button>Click me</button>
HTML Lists
HTML lists are defined with <ul> (unordered/bullet list) or <ol> (ordered/numbered list) tags,
followed by <li> tags (list items):
Example
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
HTML Tables
Table headers are defined with <th> tags. (bold and centered by default).
Example
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
2) CSS
CSS stands for Cascading Style Sheets
CSS describes how HTML elements are to be displayed on screen, paper, or in other
media
CSS saves a lot of work. It can control the layout of multiple web pages all at once
External stylesheets are stored in CSS files
CSS Example
<style>
</style>
CSS Syntax
The declaration block (in curly braces) contains one or more declarations separated by
semicolons.
Each declaration includes a CSS property name and a value, separated by a colon.
In the following example all <p> elements will be center-aligned, red and have a font size of 32
pixels:
Example
<style>
p {font-size:32px; color:red; text-align:center;}
</style>
<style>
p{
font-size: 32px;
color: red;
text-align: center;
}
</style>
mystyle.css
body {background-color: orange; font-family:verdana}
h1 {color: white;}
p {font-size: 20px;}
External style sheets are linked to HTML pages with <link> tags:
Example
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="mystyle.css">
<body>
</body>
</html>
Inline Style
Example
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="mystyle.css">
<body>
3) JavaScript
JavaScript is the Programming Language for the Web.
Numbers
Strings
Objects
Arrays
Functions
JavaScript Variables
Example
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Variables</h2>
<p id="demo"></p>
<script>
var x = 5;
var y = 6;
var z = x + y;
</script>
</body>
</html>
o/p
JavaScript Variables
JavaScript Numbers
JavaScript has only one type of number. Numbers can be written with or without decimals.
Example
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Numbers</h2>
<script>
var x = 3.14;
var y = 3;
document.getElementById("demo").innerHTML = x + "<br>" + y;
</script>
</body>
</html>
o/p
JavaScript Numbers
3.14
3
MySQL Database
What is MySQL?
The data in a MySQL database are stored in tables. A table is a collection of related data, and it
consists of columns and rows.
Databases are useful for storing information categorically. A company may have a database with
the following tables:
Employees
Products
Customers
Orders
PHP combined with MySQL are cross-platform (you can develop in Windows and serve
on a Unix platform)
Database Queries
We can query a database for specific information and have a recordset returned.
The query above selects all the data in the "LastName" column from the "Employees" table.
Apache HTTP Server is a free and open-source web server that delivers web content through the
internet. It is commonly referred to as Apache and after development, it quickly became the most
popular HTTP client on the web. It’s widely thought that Apache gets its name from its
development history and process of improvement through applied patches and modules but that
was corrected back in 2000. It was revealed that the name originated from the respect of the
Native American tribe for its resiliency and durability.
Apache is just one component that is needed in a web application stack to deliver web content.
One of the most common web application stacks involves LAMP, or Linux, Apache, MySQL,
and PHP.
Linux is the operating system that handles the operations of the application. Apache is the web
server that processes requests and serves web assets and content via HTTP. MySQL is the
database that stores all your information in an easily queried format. PHP is the programming
language that works with apache to help create dynamic web content.
Firewalls help protect the web application from both external threats and internal vulnerabilities
depending on where the firewalls are configured. Load Balancers help distribute traffic across
the web servers which handle the HTTP(S) requests (this is where Apache comes in) and
application servers (servers that handle the functionality and workload of the web app.) We also
have Database Servers, which handle asset storage and backups. Depending on your
infrastructure, your database and application can both live on the same server although it’s
recommended to keep those separate.
NOTE: This assumes that you are comfortable with administering a Windows system and can
use the command line. I never use Windows and I managed, but this may not be the quickest or
most efficient way to do things. Make sure your Windows installation is in good shape, you clear
out all the junk and stuff making it run slower (because installing all this server software
certainly isn't going to make it run faster!) and that you have installed any outstanding updates.
Install the MySQL database server on your PC. We will do this using the 'MSI' one-click installer for
Windows. Go to http://dev.mysql.com/downloads/ and download the 'MySQL Installer for Windows'.
At the time of writing this was from a very obvious graphic at the top of the screen (which I missed
the first time).
Run the installation. Click...
Install MySQL products
Accept the license
Allow the version check (optional)
At 'Choose a Setup Type' accept the "Developer Default" and click Next
A number of downloads of required software may be identified. Click Execute and follow
onscreen instructions to install them.
At 'Installation progress' screen, hit Execute - the MySQL software will be installed
At 'Configuration overview' hit Next to go to the basic configuration screen.
Accept all the defaults on the 'MySQL Server Configuration' and hit Next.
On the password screen, supply a password for the 'root' (main administrator) user. Make sure it's
one you won't forget. You can also create a 'User' account just for Moodle with more restricted
access if you like. This would be good practice on a public server but just using the 'root' user
will suffice for testing.
On the Service details page, accept the defaults and hit Next and then Next a couple more times
for the configuration progress.
Click Finish. Job done.
MySQL Workbench will open. Under Server Administration (right hand column, double click 'Local
MySQL56' (or whatever you called it). A box should pop up asking for the root password. Enter the
password you supplied
The server management screen should appear. You don't have to worry too much about this. It just
shows the install is working.
...you may well get a warning about the server name. Don't worry about it. Don't close this
window, you will need it again in a minute.
To test it worked type 'http://localhost' into your browser. You should get a screen up to the effect
that Apache is installed and working.
You now need to edit Apache's httpd.conf file. In the file explorer navigate to C:\Apache24\conf\
httpd.conf. Open it in Notepad . At the end of this file (or wherever you like if you want to be
more organised) add the following lines:
The version of the module file matters (2_4 in this case). It MUST match the Apache version
installed.
In the same file. Search for the line starting DirectoryIndex. Change it as follows
Now, navigate to C:\PHP, and copy php.ini-development to php.ini. Edit this file, find the
following lines and modify them as follows (all should exist already):
memory_limit = 256M
post_max_size = 128M
upload_max_filesize = 128M
You need to specify the extensions required for Moodle. Find the 'Dynamic Extensions' section
and change the following lines (uncomment and add the correct path):
extension=c:/php/ext/php_curl.dll
extension=c:/php/ext/php_gd2.dll
extension=c:/php/ext/php_intl.dll
extension=c:/php/ext/php_mbstring.dll
extension=c:/php/ext/php_mysqli.dll
extension=c:/php/ext/php_openssl.dll
extension=c:/php/ext/php_soap.dll
extension=c:/php/ext/php_xmlrpc.dll
(these are a minimum. You may need others - e.g. LDAP - for specific functions) ...and save.
Back in the 'cmd' window for Apache, you need to restart it to load your changes...
httpd -k restart
Navigate to C:\Apache24\htdocs and create a file called 'test.php'. I had to change a file explorer
setting to create .php files - Organise > Folder and search options > View and then untick 'Hide
extensions for known file types'.
<?php phpinfo();
And then, in your browser, navigate to http://localhost/test.php. You should see a screen with
masses of information and the PHP logo at the top. Check a few lines down for 'Loaded
Configuration File' and make sure it says c:\php\php.ini.
Anyone using MySQL on a computer connected to the Internet should read this section to avoid
the most common security mistakes.
In discussing security, it is necessary to consider fully protecting the entire server host (not just
the MySQL server) against all types of applicable attacks: eavesdropping, altering, playback, and
denial of service. We do not cover all aspects of availability and fault tolerance here.
MySQL uses security based on Access Control Lists (ACLs) for all connections, queries, and
other operations that users can attempt to perform. There is also support for SSL-encrypted
connections between MySQL clients and servers. Many of the concepts discussed here are not
specific to MySQL at all; the same general ideas apply to almost all applications.
o Try mysql -u root. If you are able to connect successfully to the server without being
asked for a password, anyone can connect to your MySQL server as the
MySQL root user with full privileges! Review the MySQL installation instructions,
paying particular attention to the information about setting a root password.
See Section 3.4, “Securing the Initial MySQL Account”.
o Use the SHOW GRANTS statement to check which accounts have access to what.
Then use the REVOKE statement to remove those privileges that are not necessary.
Do not store cleartext passwords in your database. If your computer becomes compromised,
the intruder can take the full list of passwords and use them. Instead, use SHA2() or some
other one-way hashing function and store the hash value.
To prevent password recovery using rainbow tables, do not use these functions on a plain
password; instead, choose some string to be used as a salt, and use hash(hash(password)
+salt) values.
Assume that all passwords will be subject to automated cracking attempts using lists of
known passwords, and also to targeted guessing using publicly available information about
you, such as social media posts. Do not choose passwords that consist of easily cracked or
guessed items such as a dictionary word, proper name, sports team name, acronym, or
commonly known phrase, particularly if they are relevant to you. The use of upper case
letters, number substitutions and additions, and special characters does not help if these are
used in predictable ways. Also do not choose any password you have seen used as an
example anywhere, or a variation on it, even if it was presented as an example of a strong
password.
Instead, choose passwords that are as long and as unpredictable as possible. That does not
mean the combination needs to be a random string of characters that is difficult to remember
and reproduce, although this is a good approach if you have, for example, password
manager software that can generate and fill such passwords and store them securely. A
passphrase containing multiple words is easy to create, remember, and reproduce, and is
much more secure than a typical user-selected password consisting of a single modified
word or a predictable sequence of characters. To create a secure passphrase, ensure that the
words and other items in it are not a known phrase or quotation, do not occur in a
predictable order, and preferably have no previous relationship to each other at all.
Invest in a firewall. This protects you from at least 50% of all types of exploits in any
software. Put MySQL behind the firewall or in a demilitarized zone (DMZ).
For example, /server-info exposes the Apache version along with the OpenSSL version. In the
past, an attacker could use this information to find out whether the server uses a version of
OpenSSL that is vulnerable to the Heartbleed bug.
You can disable this directive by commenting out the entire mod_info module in
the httpd.conf Apache configuration file:
When enabled, the <Location /server-status> directive lists information about server performance,
such as server uptime, server load, current HTTP requests, and client IP addresses. An attacker
may use this information to craft an attack against the web server.
You can disable this directive by commenting it out in the httpd.conf Apache configuration file:
#<Location /server-status>
# SetHandler server-status
# Order deny,allow
# Deny from all
# Allow from .your_domain.com
#</Location>
3. Disable the ServerSignature Directive
The ServerSignature directive adds a footer to server-generated documents. This footer includes
information about your Apache configuration such as the version of Apache and the operating
system. To restrict Apache from displaying this sensitive information, you need to disable this
directive in your httpd.conf Apache configuration file:
ServerSignature Off
The ServerTokens directive controls the information that is sent back in the Server response
header field. You can use different syntaxes in this directive, as listed in
the Apache ServerTokens documentation. The ServerTokens directive should be set to Prod in
order to instruct Apache to return only Apache in the server response headers. This can be done
by including the following directive in your httpd.conf Apache configuration file:
ServerTokens Prod
Directory listing lets you view complete directory contents. If this option is enabled, an attacker
can simply discover and view any file. This could potentially lead to the attacker decompiling
and reverse engineering an application in order to obtain the source code. They can then analyze
the source code for possible security flaws or obtain more information about an application, such
as database connection strings, passwords to other systems, etc. You can disable directory listing
by setting the Options directive in the Apache httpd.conf file:
<Directory /your/website/directory>
Options -Indexes
</Directory>
A default installation of the Apache HTTP server may include many pre-installed and enabled
modules that you do not need. To add insult to injury, some web server administrators have a
tendency to take the path of least resistance and enable all the remaining modules in httpd.conf,
so as to ensure that everything works without a hitch. This, however, also opens up the Apache
server to any security issues that might exist or be discovered in the future for the enabled
modules.
The Apache module documentation lists and explains all the modules available for Apache.
Research the modules that you have enabled and make sure that they are really required for the
functionality of the website. Unnecessary modules should be disabled by commenting out a
specific LoadModule line.
By default, Apache runs under the daemon user and group. However, it is best practice to run
Apache using a non-privileged account. Furthermore, if two processes (such as Apache and
MySQL) are running using the same user and group, issues in one process might lead to exploits
in the other process. To change Apache user and group, you need to change
the User and Group directives in the Apache httpd.conf configuration file.
User apache
Group apache
To secure Apache, you may want to disable certain services, such as CGI execution and
symbolic links, if these are not needed. You can disable these services using the Options directive
in the httpd.conf configuration file and you may also disable these services for a particular
directory only. The below example shows what you need to include in
your httpd.conf configuration file to disable CGI script execution, symbolic links, and server-side
includes for your web server root directory and its subdirectories.
<Directory /your/website/directory>
Options -ExecCGI -FollowSymLinks -Includes
</Directory>
We recommend that you follow the ModSecurity manual to install mod_security to improve your
web server security and protect against a multitude of attacks including distributed denial of
service attacks (DDOS). You can also temporarily use ModSecurity to protect against certain
attacks like SQL Injection and Cross-site Scripting until vulnerabilities are fixed by the
developer.
10. Enable Logging
Apache logging provides detailed information about client requests made on your web server,
hence enabling such logging will prove useful when investigating the cause of particular issues.
In order to enable logging the mod_log_config module needs to be included from the Apache
httpd.conf file. This module provides the TransferLog, LogFormat, and CustomLog directives
which are respectively used to create a log file, specify a custom format, and creating and
formatting a log file in one step. As seen below, the LogFormat directive is used to specify a
custom logging format – in this case the referrer and browser of each request are logged along
with the default logging parameters. Then, the CustomLog directive will be used to instruct
Apache to use this logging format