(IWD) - Lab Manual
(IWD) - Lab Manual
(IWD) - Lab Manual
Institute’s Vision:
Institute’s Mission:
Department’s Vision:
Department’s Mission:
R. C. Technical
Name Institute, Ahmedabad (640)
of institute
Certificate
Place:…………………..
Date: …………………..
By using this lab manual, students can read procedure one day in advance to actual
performance day of practical experiment which generates interest and also, they can have idea of
judgement of magnitude prior to performance. This in turn enhances predetermined outcomes
amongst students. Each and every Experiment /Practical in this manual begins by competency,
industry relevant skills, course outcomes as well as practical outcomes which serve as a key role for
doing the practical. The students will also have a clear idea of safety and necessary precautions to be
taken while performing experiment.
This manual also provides guidelines to lecturers to facilitate student-centered lab activities
for each practical/experiment by arranging and managing necessary resources in order that the
students follow the procedures with required safety and necessary precautions to achieve outcomes.
It also gives an idea that how students will be assessed by providing Rubrics.
In our day-to-day lives, we use a number of web applications, such as online ticket or hotel
booking, e-commerce, social networks, email, etc. All of these web applications are stored on a remote
server, delivered over the Internet and accessed through a browser interface. PHP is an open-source,
server-side scripting language designed specifically for web applications. PHP is one of the most
popular choices among developers to develop dynamic, interactive, secure and database-driven web
applications. In the growing field of Web technologies, it is essential for diploma-passing students to
learn the PHP language to help them build web applications. The goal of this course is to develop web
development skills in students using the server-side scripting language PHP. Students will learn the
integration of HTML, PHP and MySQL database to develop web applications.
Although we try our level best to design this lab manual, but always there are chances of
improvement. We welcome any suggestions for improvement.
Programme Outcomes (POs):
Following programme outcomes are expected to be achieved through the practical of the course:
1. Basic and Discipline specific knowledge: Apply knowledge of basic mathematics, science and
engineering fundamentals and engineering specialization to solve the engineering problems.
2. Problem analysis: Identify and analyse well-defined engineering problems using codified standard
methods.
3. Design/development of solutions: Design solutions for engineering well-defined technical
problems and assist with the design of systems components or processes to meet specified needs.
4. Engineering Tools, Experimentation and Testing: Apply modern engineering tools and
appropriate technique to conduct standard tests and measurements.
5. Engineering practices for society, sustainability and environment: Apply appropriate technology
in context of society, sustainability, environment and ethical practices.
6. Project Management: Use engineering management principles individually, as a team member or
a leader to manage projects and effectively communicate about well-defined engineering
activities.
7. Life-long learning: Ability to analyse individual needs and engage in updating in the context of
technological changes in field of engineering.
Practical Outcome - Course Outcome matrix
Course Outcomes (COs):
a. CO1: Develop PHP scripts using variables, operators and control structures.
b. CO2: Develop PHP scripts using arrays and functions.
c. CO3: Develop PHP scripts by applying object oriented concepts.
d. CO4: Develop web pages using form controls with validation to collect user inputs in PHP.
e. CO5: Develop and host interactive websites using PHP and MySQL database.
Sr.
No Experiment/Practical Outcome CO1 CO2 CO3 CO4 CO5
.
Environment Setup √ - - - -
1 i. Install and configure PHP, Web Server and MySQL
database using XAMPP/WAMP/LAMP/MAMP.
ii. Create a web page that displays “Hello World.”
2 Form Introduction - - - √ -
i. Create a web page that collects user information
using a form and displays it when the user clicks the
submit button.
3 Variables, Operators and Expressions √ - - - -
i. Write a script to implement a simple calculator for
mathematical operations.
ii. A company has following payment scheme for their
staff:
a. Net Salary = Gross Salary – Deduction
b. Gross Salary = Basic pay + DA + HRA + Medical
c. Deduction = Insurance + PF
Where, DA (Dearness Allowance) = 50% of Basic pay
HRA (House Rent Allowance) = 10% of Basic pay
Medical = 4% of Basic pay
Insurance = 7% of Gross salary
PF (Provident Fund) = 5% of Gross salary
Write a script to take the basic salary of an employee
as input and calculate the net payment to any
employee.
4 Decision making statements √ - - - -
i. Write a script that reads the name of the car and
displays the name of the company the car belongs to
as per the below table:
Car Company
Safari, Nexon, Tigor, Tiago Tata
XUV700, XUV300, Bolero Mahindra
i20, Verna, Venue, Creta Hyundai
Swift, Alto, Baleno, Brezza Suzuki
ii. Write a script to read the marks of 4 subjects and
display the result as per the below instructions:
GTU
Mark-Range
GRADE
AA 85 - 100
AB 75 - 84
BB 65 - 74
BC 55 - 64
CC 45 - 54
CD 40 - 44
DD 35 - 39
FF < 35 (FAIL)
a. Each of the four subjects is worth 100 marks.
b. If a student gets less than 35 marks in any subject,
then he/she will be marked as FAIL, otherwise he/she
will be marked as PASS.
The result contains the grade of each individual subject
in tabular format as per the above table.
Loops
iii. Write a script to display Fibonacci numbers up to a
given term.
iv. Write a script to display a multiplication table for
the given number.
Arrays - √ - - -
5
i. Write a script to calculate the length of a string and
count the number of words in the given string without
using string functions.
ii. Write a script to sort a given indexed array.
iii. Write a script to perform 3 x 3 matrix
Multiplication.
iv. Write a script to encode a given message into
equivalent Morse code.
6 Functions - √ - - -
i. Consider a currency system in which there are
notes of 7 denominations, namely Rs. 1, Rs. 2, Rs. 5, Rs.
10, Rs. 20, Rs. 50 and Rs. 100. Write a function that
computes the smallest number of notes that will
combine for a given amount of money.
ii. Write scripts using string functions:
a. to check if the given string is lowercase or not.
b. to reverse the given string.
c. to remove white spaces from the given string.
d. to replace the given word from the given string.
iii. Write scripts using math functions:
a. to generate a random number between the given
range.
b. to display the binary, octal and hexadecimal of a
given decimal number.
c. to display the sin, cos and tan of the given angle.
iv. Write a script to display the current date and time
in different formats.
7 OOP Concepts - - √ - -
i. Write a script to:
a. Define a class with constructor and destructor.
b. Create an object of a class and access its public
properties and methods.
ii. Write a script that uses the set attribute and get
attribute methods to access a class’s private attributes
of a class.
iii. Write a script to demonstrate single inheritance.
iv. Write a script to demonstrate multiple inheritance.
v. Write a script to demonstrate multilevel
inheritance.
vi. Write a script to demonstrate method overriding.
vii. Write a script to demonstrate method overloading
based on the number of arguments.
viii. Write a script to demonstrate a simple interface.
ix. Write a script to demonstrate a simple abstract
class.
x. Write a script to demonstrate cloning of objects.
8 Forms - - - √ -
i. Create a web page using a form to collect employee
information.
ii. Extend practical - 8(i) to validate user information
using regular expressions.
iii. Create two distinct web pages to demonstrate
information passing between them using URL - Get
method.
iv. Create two different web pages to demonstrate
information passing between web pages using Hidden
variables – Post method.
9 Session, Cookies - - √ -
-
i. Create web pages to demonstrate passing
information using Session.
ii. Write a script to demonstrate storing and retrieving
information from cookies.
10 Database - - - - √
i. Create a web page that reads employee
information using a form and stores it in the database.
ii. Create a web page for employee log-in.
iii. Write a script to upload an image to the server.
iv. After an employee logs in, create a Home web page
that displays basic employee information.
v. Create a web page to delete employee profiles
from the database.
vi. Create a web page that allows employees to
change their password.
11 Email, PDF, JSON - - - - √
i. Write a script to generate a salary slip for an
employee in PDF format.
ii. Write a script to send an email.
iii. Write a script to convert an associative array into
JSON string format and vice versa.
Simple Web Application √ √ √ √ √
12 Create a simple web application for Employee
Management with 3-4 web pages and host it using
cPanel and Filezilla.
Industry Relevant Skills
The following industry relevant skills of the competency “Develop Interactive Web application
using PHP and MySQL” are expected to be developed in the student by undertaking the
practical of this laboratory manual.
1. Install and configure software as per requirements.
2. Write code for the given problem.
3. Debug program to fix errors.
4. Follow Coding Guidelines.
Guidelines to Teachers
1. Couse faculty should demonstrate experiment with all necessary implementation
strategies described in curriculum.
2. Couse faculty should explain industrial relevance before starting of each experiment.
3. Course faculty should involve & give opportunity to all students for hands on experience.
4. Course faculty should ensure mentioned skills are developed in the students by asking.
5. Utilise 2 hrs of lab hours effectively and ensure completion of write up with quiz also.
6. Encourage peer to peer learning by doing same experiment through fast learners.
Date: _____________
Objectives:
A development environment is required to write, compile, run, and debug any
application. This practical will help student to set up PHP environment for executing
PHP program using different server like XAMPP or WAMP server.
Practical Outcomes:
Install and configure web application development environment for PHP and
MySQL.
1|Page
Introduction to Web Development (4340704)
Prerequisite Theory:
XAMPP is one of the most popular software pack to set up web application development
environment for PHP with all required software components. XAMPP is an Open Source
AMP stack which stands for Cross platform, Apache, MariaDB, PHP and Perl. Apache is
cross platform web server, MariaDB is the most widely used database developed by
MySQL, PHP is a backend scripting language and Perl is a programming used for web
development. X denotes Cross-platform, which means that it can work on different
platforms such as Windows, Linux, and macOS.
XAMPP allows a local host or server to test its website and clients on computers and
laptops before releasing them to the main server. It provides a suitable environment for
testing and verifying the functioning working of projects based on Apache, Perl, MySQL
database, and PHP on the host's system. It also includes administrative tools such as
phpMyAdmin, Filezilla FTP Server, Mercury mail server and JSP Tomcat server.
Resources Required:
Sr.
Instrument /Components Configuration/Specification
No
Processor:
1. Computer System RAM:
Operating System:
Procedure:
Below steps describes installation of XAMPP on Windows operating system. Steps are
similar for Linux and Mac operating systems.
i. Install XAMPP
Open the XAMPP website. Go to https://www.apachefriends.org/index.html in
your computer's web browser.
2|Page
Introduction to Web Development (4340704)
Because User Account Control (UAC) restricts writing access to the C: drive and can
interfere with the XAMPP installation, it is recommended that this be disabled for
the duration of the installation.
After that the start screen of the XAMPP setup wizard should appear automatically.
Click on ‘Next’ to configure the installation settings.
3|Page
Introduction to Web Development (4340704)
Under ‘Select Components’, you have the option to exclude individual components
of the XAMPP software bundle from the installation. But for a full local test server,
we recommend you install using the standard setup and all available components.
After making your choice, click ‘Next’.
In this next step, you have the chance to choose where you’d like the XAMPP
software packet to be installed. If you opt for the standard setup, then a folder with
the name xampp will be created under C:\ for you. After you’ve chosen a location,
click ‘Next’.
4|Page
Introduction to Web Development (4340704)
5|Page
Introduction to Web Development (4340704)
Once all the preferences have been decided, click to start the installation. The setup
wizard will unpack and install the selected components and save them to the
designated directory. This process may take few minutes.
Your Firewall may interrupt the installation process to block the some components
of the XAMPP. Use the corresponding check box to enable communication between
the Apache server and your private network or work network. Remember that
making your XAMPP server available for public networks isn’t recommended.
Once all the components are unpacked and installed, you can close the setup
wizard by clicking on ‘Finish’. Click to tick the corresponding check box and open
the XAMPP Control Panel once the installation process is finished.
XAMPP Control Panel provides controls for the individual components of your
xampp test server. The control panel user interface allows you to start or stop
individual modules: Apache, MySQL, FileZilla, Mercury and Tomcat. The XAMPP
Control Panel also offers you various other buttons, including:
Config: allows you to configure the XAMPP as well as the individual components
6|Page
Introduction to Web Development (4340704)
Individual modules can be started or stopped on the XAMPP Control Panel through
the corresponding buttons under ‘Actions’. You can see which modules have been
started because their names are highlighted green under the ‘Module’ title.
7|Page
Introduction to Web Development (4340704)
numerous links to websites for useful information as well as the open source
project BitNami, which offers you many different applications for your XAMPP, like
WordPress or other content management systems. Alternatively, you can reach the
dashboard through localhost/dashboard/.
You can use the Admin button of your database module to open phpMyAdmin.
Here, you can manage the databases of your web projects that you’re testing on
your XAMPP. Alternatively, you can reach the administration section of your MySQL
database via localhost/phpmyadmin/
8|Page
Introduction to Web Development (4340704)
You can create a new PHP file with below code in your editor and storing it as
test.php in your ‘test’ folder (C:\xampp\htdocs\test):
Now open a web browser and load your PHP page via localhost/test/test.php. If
your browser window displays the words ‘Hello World’, then you’ve successfully
installed and configured your XAMPP.
Output:
Snapshot of XAMPP Control Panel after installation.
Output:
9|Page
Introduction to Web Development (4340704)
Output:
10 | P a g e
Introduction to Web Development (4340704)
11 | P a g e
Introduction to Web Development (4340704)
B) httpd.conf
C) my.ini
D) config.inc.php
Which port number is used by default for the MySQL database in XAMPP?
A) Port 80
B) Port 443
C) Port 3306
D) Port 8080
Which of the following is not a security risk associated with using XAMPP?
A) Leaving the default username and password for the MySQL database unchanged
B) Running XAMPP on a publicly accessible network
C) Disabling the firewall on your computer
D) Using weak or easily guessable passwords for XAMPP components
Which of the following is a tool included in XAMPP that allows you to administer
MySQL databases?
A) phpMyAdmin
B) Apache Tomcat
C) Microsoft SQL Server Management Studio
D) Oracle SQL Developer
Which of the following XAMPP components allows you to run PHP scripts?
A) Apache HTTP Server
B) MySQL
C) Perl
D) Node.js
References:
https://www.apachefriends.org
https://phpandmysql.com/extras/installing-xampp
https://www.youtube.com/watch?v=at19OmH2Bg4
https://www.youtube.com/watch?v=PaDgry5QAt4
https://www.w3schools.com/php
12 | P a g e
Introduction to Web Development (4340704)
Assessment Rubrics:
% of
Criteria Rubrics Marks
point
Excellent (10-8 marks): Completed programs/scripts
correctly as per the requirements.
C1: Adequate (7-6 marks): Completed programs/scripts
Program correctly with approx. 70% requirements.
50 %
Completeness/ Poor (5-4 marks): Completed programs/scripts correctly
Correctness with 70% - 50% requirements.
Unsatisfactory (0-3 marks): Completed programs/ scripts
correctly with less than 50% requirements.
Excellent (10-8 marks): The code is clean, well-organized and
very easy to understand.
Adequate (7-6 marks): The code is fairly easy to read and
C2: understand.
25 %
Readability Poor (5-4 marks): The code is readable only by someone who
knows what it is supposed to be doing.
Unsatisfactory (0-3 marks): The code is poorly organized and
very difficult to understand.
Excellent (10-8 marks):
• Coding standards are followed in complete code while
naming variables/functions/ classes, explaining the
purpose of variables/ functions/classes.
• The Complete code is well-documented with comments
explaining the code.
Adequate (7-6 marks):
• Coding standards are followed in most of the code while
naming variables/functions/ classes, explaining the
C3:
purpose of variables/ functions/classes.
Coding
25 % • Most of the code is documented with comments
Standards/ explaining the code.
Documentation
Poor (5-4 marks):
• Coding standards are followed in very little code while
naming variables/functions/ classes, explaining the
purpose of variables/ functions/classes.
• Very little code is documented with comments
explaining the code.
Unsatisfactory (0-3 marks):
• Coding standards are not followed properly.
• Proper comments are not written explaining the code.
Total Marks for Practical = 0.5 * (Marks of C1) + 0.25 * (Marks of C2) + 0.25 * (Marks of C3)
13 | P a g e
Introduction to Web Development (4340704)
Date: _____________
Objectives:
Forms are important component of the web application that allows it to collect
information from the users. Most websites use different forms for various tasks such as
log in, registration, contact us, and application specific information collection. Now a
days you rarely see any website without a form. This practical will help students to
design a form to collect user data using PHP.
Practical Outcomes:
Develop web pages using Form controls such as text box, button, check box, radio
button, text area etc.
14 | P a g e
Introduction to Web Development (4340704)
Prerequisite Theory:
Web forms are one of the most common ways for a user to interact with a
web application. Forms allow users to enter data, which is typically sent to a web server
for processing and storage or used on the client-side to update the interface in some
way immediately.
The HTML of a web form is made up of one or more form controls (also known as
widgets) and some additional elements to help structure the overall form - these are
commonly referred to as HTML forms. Most common controls are single or multi-line
text boxes, dropdown boxes, buttons, checkboxes and radio buttons. There are some
other elements such as date, time, day color, file etc. Form controls can also be
programmed to enforce specific formats or values to be entered (form validation).
Define HTML Form:
The HTML <form> element is used to create an HTML form for user input:
<form>
...
form elements
...
</form>
• The <label> tag defines a label for many form elements. The <label> element is
useful for screen-reader users, because the screen-reader will read out loud the
label when the user focus on the input element.
• The <input type="submit"> defines a button for submitting the form data to a
form-handler. The form-handler is typically a file on the server with a script for
processing input data.
• The action attribute defines the action to be performed when the form is
submitted. Usually, the form data is sent to a file on the server when the user clicks
on the submit button.
• The method attribute specifies the HTTP method to be used when submitting the
form data. The form-data can be sent as URL variables (with method="get") or as
HTTP post transaction (with method="post").
15 | P a g e
Introduction to Web Development (4340704)
• The HTML id attribute is used to specify a unique id for an HTML element. You
cannot have more than one element with the same id in an HTML document.
• Each input field must have a name attribute to be submitted. If the name attribute
is omitted, the value of the input field will not be sent at all. It is used by PHP script
to read form data from that input element.
• The type attribute defines type of input element. By default value of the type
attribute is "text". Different types of input elements are as follow:
TextBox:
The <input type="text"> provides a single-line input field to input text.
16 | P a g e
Introduction to Web Development (4340704)
Radio Button:
Radio Button allows user to select only one choice from a limited number of choices.
Check Box:
Check Box allows a user to select zero or more choices from a limited number of choices.
Resources Required:
17 | P a g e
Introduction to Web Development (4340704)
Sr.
Instrument /Components Configuration/Specification
No
Processor:
1. Computer System RAM:
Operating System:
18 | P a g e
Introduction to Web Development (4340704)
Output:
19 | P a g e
Introduction to Web Development (4340704)
20 | P a g e
Introduction to Web Development (4340704)
c) initial
d) none of the above
Which attribute is used to specify the maximum number of characters allowed in
an input element?
A) maxlength
B) maxchar
C) length
D) limit
Which attribute is used to specify a pattern for input validation?
A) pattern
B) validate
C) input-pattern
D) regex
Which attribute is used to specify whether an input field should be disabled?
A) disabled
B) enable
C) active
D) none of the above
Which input type in HTML 5 is used for creating a dropdown list?
a) select
b) dropdown
c) menu
d) list
References:
https://www.w3schools.com/html/html_forms.asp
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form
https://www.quackit.com/html/codes/html_form_code.cfm
https://www.javatpoint.com/html-form
https://www.geeksforgeeks.org/html-forms
https://www.tutorialspoint.com/html/html_forms.htm
21 | P a g e
Introduction to Web Development (4340704)
Assessment Rubrics:
% of
Criteria Rubrics Marks
point
Excellent (10-8 marks): Completed programs/scripts
correctly as per the requirements.
C1: Adequate (7-6 marks): Completed programs/scripts
Program correctly with approx. 70% requirements.
50 %
Completeness/ Poor (5-4 marks): Completed programs/scripts correctly
Correctness with 70% - 50% requirements.
Unsatisfactory (0-3 marks): Completed programs/ scripts
correctly with less than 50% requirements.
Excellent (10-8 marks): The code is clean, well-organized and
very easy to understand.
Adequate (7-6 marks): The code is fairly easy to read and
C2: understand.
25 %
Readability Poor (5-4 marks): The code is readable only by someone who
knows what it is supposed to be doing.
Unsatisfactory (0-3 marks): The code is poorly organized and
very difficult to understand.
Excellent (10-8 marks):
• Coding standards are followed in complete code while
naming variables/functions/ classes, explaining the
purpose of variables/ functions/classes.
• The Complete code is well-documented with comments
explaining the code.
Adequate (7-6 marks):
• Coding standards are followed in most of the code while
naming variables/functions/ classes, explaining the
C3:
purpose of variables/ functions/classes.
Coding
25 % • Most of the code is documented with comments
Standards/ explaining the code.
Documentation
Poor (5-4 marks):
• Coding standards are followed in very little code while
naming variables/functions/ classes, explaining the
purpose of variables/ functions/classes.
• Very little code is documented with comments
explaining the code.
Unsatisfactory (0-3 marks):
• Coding standards are not followed properly.
• Proper comments are not written explaining the code.
Total Marks for Practical = 0.5 * (Marks of C1) + 0.25 * (Marks of C2) + 0.25 * (Marks of C3)
22 | P a g e
Introduction to Web Development (4340704)
Objectives:
Variables, Operators and Expressions are core part of any programming language.
• Variables are used to store data.
• Operators are used to perform various types of operations on data.
• Anything that you write in PHP script is an expression.
This practical will allow students to practise writing PHP scripts that use variables,
operators, and expressions to solve simple problems.
23 | P a g e
Introduction to Web Development (4340704)
Programming skills.
Debugging skills.
Practical Outcomes:
Use PHP variables to store data in PHP scripts.
Perform operation on data using operator in PHP scripts.
Prerequisite Theory:
Variables:
A variable is a named area of storage, where you can store a value.
• In PHP, variables are represented by a dollar sign ($) followed by the name of
the variable.
• Variable names are case-sensitive. For example, $var and $Var are two
different variables.
• A valid variable name starts with a letter or underscore, followed by any number
of letters, numbers, or underscores.
• A PHP variable name cannot contain spaces.
• For example, $enrollmentno, $subject_name, $_itemid are valid
variable names and $12var, $student name, part_id are invalid variable
names.
• PHP is loosely-typed language, so it doesn’t need to specify data type of
variables. It automatically analyse assigned value and defined data type of
variable.
• Assignment Operator (=) is used to assign the value to a variable. For example,
$subject_name = “Introduction to Web Development”;
PHP has total eight different data types which can be used to define variables:
• Integers − whole numbers, without a decimal point. E.g. – 415, 8341.
• Doubles − floating-point numbers. E.g. – 12.5, 3.14.
• Booleans − two possible values either TRUE or FALSE.
• NULL − special type that only has one value: NULL.
24 | P a g e
Introduction to Web Development (4340704)
Assignment Operators:
Operator Name Example Description
$a = $b Value of right operand is assigned
= Assign
to left operand
+= Add then assign $a += $b Same as $a = $a + $b
-= Subtract then assign $a -= $b Same as $a = $a - $b
*= Multiply then assign $a *= $b Same as $a = $a * $b
Divide then assign $a /= $b
/= Same as $a = $a / $b
(Quotient)
Divide then assign $a %= $b
%= Same as $a = $a % $b
(Reminder)
25 | P a g e
Introduction to Web Development (4340704)
Bitwise Operators:
Operator Name Example Description
$a & $b Bitwise AND operation between $a
& Bitwise AND
and $b
$a | $b Bitwise OR operation between $a
| Bitwise OR
and $b
$a ^ $b Bitwise XOR operation between $a
^ Bitwise XOR
and $b
~ Bitwise NOT ~ $a Bitwise NOT operation on $a
<< Left shift $a << $b Left shift bits of $a by $b steps
>> Right shift $a >> $b Right shift bits of $a by $b steps
Comparison Operators:
Operator Name Example Description
== Equal $a == $b Returns TRUE if $a is equal to $b
$a != $b Returns TRUE if $a is not equal to
!= Not equal
$b
$a <> $b Returns TRUE if $a is not equal to
<> Not equal
$b
$a === $b Returns TRUE if $a and $b are
=== Identical
equal and of same data type
$a !== $b Returns TRUE if $a and $b are not
!== Not identical
equal or of different data type
< Less than $a < $b Returns TRUE if $a is less than $b
$a > $b Returns TRUE if $a is greater than
> Greater than
$b
Less than or equal $a <= $b Returns TRUE if $a is less than or
<=
to equal to $b
Greater than or $a >= $b Returns TRUE if $a is greater than
>=
equal to or equal to $b
$a <=> $b Return -1 if $a is less than $b
<=> Spaceship Return 0 if $a is equal $b
Return 1 if $a is greater than $b
26 | P a g e
Introduction to Web Development (4340704)
Logical Operators:
Operator Name Example Description
$a and $b Returns TRUE if both $a and $b are
and Logical AND
true
$a or $b Returns TRUE if either $a or $b is
or Logical OR
true
$a xor $b Returns TRUE if either $a or $b is
xor Logical XOR
true, but not both are TRUE
! Logical NOT ! $a Returns TRUE if $a is FALSE
$a && $b Returns TRUE if both $a and $b are
&& Logical AND
true
$a || $b Returns TRUE if either $a or $b is
|| Logical OR
true
String Operators:
Operator Name Example Description
. Concatenation $a . $b Concatenate both $a and $b
Concatenation and $a .= $b
.= Same as $a = $a . $b
assign
Expressions
In PHP, anything that has a value is an expression, so most of the statements you write
in PHP scrips are expression. For Example:
$a = $b; // $b is an expression
$a = $b * $c; // $b * $c is an expression
$a = sum($b, $c); // sum($b, $c) is an expression
$b++; // $b++ is an expression
Resources Required:
Sr.
Instrument /Components Configuration/Specification
No
Processor:
1. Computer System RAM:
Operating System:
27 | P a g e
Introduction to Web Development (4340704)
28 | P a g e
Introduction to Web Development (4340704)
Output:
Source Code:
29 | P a g e
Introduction to Web Development (4340704)
Output:
30 | P a g e
Introduction to Web Development (4340704)
31 | P a g e
Introduction to Web Development (4340704)
References:
https://www.php.net/manual/en/language.variables.php
https://www.php.net/manual/en/language.expressions.php
https://www.w3schools.com/php/php_variables.asp
https://www.w3schools.com/php/php_operators.asp
https://www.geeksforgeeks.org/php-variables
32 | P a g e
Introduction to Web Development (4340704)
Assessment Rubrics:
% of
Criteria Rubrics Marks
point
Excellent (10-8 marks): Completed programs/scripts
correctly as per the requirements.
C1: Adequate (7-6 marks): Completed programs/scripts
Program correctly with approx. 70% requirements.
50 %
Completeness/ Poor (5-4 marks): Completed programs/scripts correctly
Correctness with 70% - 50% requirements.
Unsatisfactory (0-3 marks): Completed programs/ scripts
correctly with less than 50% requirements.
Excellent (10-8 marks): The code is clean, well-organized and
very easy to understand.
Adequate (7-6 marks): The code is fairly easy to read and
C2: understand.
25 %
Readability Poor (5-4 marks): The code is readable only by someone who
knows what it is supposed to be doing.
Unsatisfactory (0-3 marks): The code is poorly organized and
very difficult to understand.
Excellent (10-8 marks):
• Coding standards are followed in complete code while
naming variables/functions/ classes, explaining the
purpose of variables/ functions/classes.
• The Complete code is well-documented with comments
explaining the code.
Adequate (7-6 marks):
• Coding standards are followed in most of the code while
naming variables/functions/ classes, explaining the
C3:
purpose of variables/ functions/classes.
Coding
25 % • Most of the code is documented with comments
Standards/ explaining the code.
Documentation
Poor (5-4 marks):
• Coding standards are followed in very little code while
naming variables/functions/ classes, explaining the
purpose of variables/ functions/classes.
• Very little code is documented with comments
explaining the code.
Unsatisfactory (0-3 marks):
• Coding standards are not followed properly.
• Proper comments are not written explaining the code.
Total Marks for Practical = 0.5 * (Marks of C1) + 0.25 * (Marks of C2) + 0.25 * (Marks of C3)
33 | P a g e
Introduction to Web Development (4340704)
Write a script to read the marks of 4 subjects and display the result as per the below
instructions:
GTU
Mark-Range
GRADE
AA 85 - 100
AB 75 - 84
BB 65 - 74
BC 55 - 64
CC 45 - 54
CD 40 - 44
DD 35 - 39
FF < 35 (FAIL)
• Each of the four subjects is worth 100 marks.
• If a student gets less than 35 marks in any subject, then he/she will be marked
as FAIL, otherwise he/she will be marked as PASS.
The result contains the grade of each individual subject in tabular format as per the
above table.
Write a script to display Fibonacci numbers up to a given term.
Write a script to display a multiplication table for the given number.
Objectives:
This practical will help student to practice writing PHP scripts using Decision making
structure and Loops.
• Conditional statements are used to perform different actions based on different
conditions.
• Loops are used to run same block of code again and again certain number of
times.
Practical Outcomes:
Use decision making statements in PHP scripts.
Use loops in PHP scripts.
Prerequisite Theory:
Decision Making Statements:
Controls statements are used to control are used to control the flow of execution of
program based on certain conditions. In PHP, there are following decision making
statements:
• if statement
• if...else statement
• if...elseif...else statement
• switch statement
if statement:
if statement allow us to run a block of code if certain condition is true. If condition is
false it will not execute block of code.
35 | P a g e
Introduction to Web Development (4340704)
if(condition) {
Block of code // statements to execute if condition is
// true
}
if...else statement:
if...else executes a block of code if certain condition is true and another block of
code if condition is false.
if(condition) {
Block of code // statements to execute if
// condition is true
}
else {
Block of code // statements to execute if
// condition is false
}
if...elseif...else statement:
if(condition) {
Block of code // statements to execute if this
// condition is true
}
elseif(condition) {
Block of code // statements to execute if this
// condition is true
} elseif(condition) {
Block of code // statements to execute if this
// condition is true
} else {
Block of code // statements to execute if all
// conditions are false
}
switch statement:
The switch statement is used to perform different actions based on different conditions.
Use the switch statement to select one of many blocks of code to be executed.
36 | P a g e
Introduction to Web Development (4340704)
switch(n) {
case value1:
code to be executed if n== value1;
break;
case value2:
code to be executed if n== value2;
break;
case value3:
code to be executed if n== value3;
break;
case value4:
code to be executed if n== value4;
break;
......
default:
code to be executed if n != any case;
}
Loops:
Loops in PHP are used to execute the same block of code a specified number of times.
PHP supports below loop statements:
• while loop
• do...while loop
• for loop
• foreach loop
while loop:
while loop executes a block of code as long as the specified condition is true.
while(condition) {
Block of code // statements to execute
// till condition is true
}
do...while loop:
do...while loop executes a block of code once, and then repeats the loop as long as the
specified condition is true
do {
Block of code // statements to execute till
// condition is true. Executed once
// before checking condition.
} while(condition);
37 | P a g e
Introduction to Web Development (4340704)
for loop:
for loop executes a block of code a specified number of times.
foreach loop:
foreach loop executes a block of code for each element in an array.
break statement:
break statement is used to terminate the execution of a loop prematurely.
while(condition1) {
Block of code // statements to execute
// till condition1 is true
if(condition2) {
break; // exit while loop is condition2
// is true
}
}
continue statement:
continue statement is used to halt the current iteration of a loop and start next
iteration of loop. It does not terminate the loop.
while(condition1) {
if(condition2) {
continue; // if condition2 is true then
// remaining part of the loop will
// not be executed in this
// iteration
}
Block of code // statements to execute
// till condition1 is true
}
38 | P a g e
Introduction to Web Development (4340704)
Resources Required:
Sr.
Instrument /Components Configuration/Specification
No
Processor:
1. Computer System RAM:
Operating System:
Source Code:
39 | P a g e
Introduction to Web Development (4340704)
Output:
Write a script to read the marks of 4 subjects and display the result as per the below
instructions:
GTU
Mark-Range
GRADE
AA 85 - 100
AB 75 - 84
BB 65 - 74
BC 55 - 64
CC 45 - 54
CD 40 - 44
DD 35 - 39
FF < 35 (FAIL)
40 | P a g e
Introduction to Web Development (4340704)
41 | P a g e
Introduction to Web Development (4340704)
Output:
42 | P a g e
Introduction to Web Development (4340704)
Output:
43 | P a g e
Introduction to Web Development (4340704)
Output:
44 | P a g e
Introduction to Web Development (4340704)
D) foreach loop
Which of the following loop statements in PHP is used to execute a code block for
a specific number of times?
A) for loop
B) while loop
C) do-while loop
D) foreach loop
What is the output of the following code?
for ($i = 1; $i <= 10; $i++) {
if ($i == 5) {
continue;
}
echo $i;
}
A) 12345678910
B) 1234678910
C) 123468910
A) 123456789
Which of the following is used to execute a code block multiple times in PHP?
A) decision-making statement
B) loop statement
C) function
D) class
Which of the following is used to skip an iteration in a loop in PHP?
A) continue
B) break
C) return
D) exit
Which of the following is used to execute a block of code if none of the conditions
in a series of if-else statements are true?
A) if statement
B) else if statement
C) else statement
D) switch statement
45 | P a g e
Introduction to Web Development (4340704)
References:
https://www.w3schools.com/php/php_if_else.asp
https://www.w3schools.com/php/php_looping.asp
https://www.geeksforgeeks.org/php-decision-making
https://www.geeksforgeeks.org/php-loops
https://www.tutorialspoint.com/php/php_decision_making.htm
https://www.tutorialspoint.com/php/php_loop_types.htm
46 | P a g e
Introduction to Web Development (4340704)
Assessment Rubrics:
% of
Criteria Rubrics Marks
point
Excellent (10-8 marks): Completed programs/scripts
correctly as per the requirements.
C1: Adequate (7-6 marks): Completed programs/scripts
Program correctly with approx. 70% requirements.
50 %
Completeness/ Poor (5-4 marks): Completed programs/scripts correctly
Correctness with 70% - 50% requirements.
Unsatisfactory (0-3 marks): Completed programs/ scripts
correctly with less than 50% requirements.
Excellent (10-8 marks): The code is clean, well-organized and
very easy to understand.
Adequate (7-6 marks): The code is fairly easy to read and
C2: understand.
25 %
Readability Poor (5-4 marks): The code is readable only by someone who
knows what it is supposed to be doing.
Unsatisfactory (0-3 marks): The code is poorly organized and
very difficult to understand.
Excellent (10-8 marks):
• Coding standards are followed in complete code while
naming variables/functions/ classes, explaining the
purpose of variables/ functions/classes.
• The Complete code is well-documented with comments
explaining the code.
Adequate (7-6 marks):
• Coding standards are followed in most of the code while
naming variables/functions/ classes, explaining the
C3:
purpose of variables/ functions/classes.
Coding
25 % • Most of the code is documented with comments
Standards/ explaining the code.
Documentation
Poor (5-4 marks):
• Coding standards are followed in very little code while
naming variables/functions/ classes, explaining the
purpose of variables/ functions/classes.
• Very little code is documented with comments
explaining the code.
Unsatisfactory (0-3 marks):
• Coding standards are not followed properly.
• Proper comments are not written explaining the code.
Total Marks for Practical = 0.5 * (Marks of C1) + 0.25 * (Marks of C2) + 0.25 * (Marks of C3)
47 | P a g e
Introduction to Web Development (4340704)
Objectives:
In PHP, array data structure allows user to store multiple elements of similar data type
under a single variable. Array provide below advantages:
• No need to use multiple variables to store different data.
• Easy to traverse data in array using loops.
• Easy to sort data stored in array.
This practical will help student to practice writing PHP scripts using arrays.
Practical Outcomes:
Develop PHP scripts using one-dimensional, multi-dimensional and associative
arrays.
48 | P a g e
Introduction to Web Development (4340704)
Prerequisite Theory:
PHP array is a collection of similar data times stored in a single variable. It is basically an
ordered map, which contains values on the basis of keys/indexes. PHP arrays allows
traversing and processing of data items using a single loop. There are three types of
arrays in PHP.
1. Indexed arrays
2. Associative arrays
3. Multi-dimensional arrays
Indexed/Numeric arrays
These type of arrays can store data of any type. They have integer indexes that start at
zero by default. The Indexed array can be created as follow:
$subject_codes[0] = 4330701;
$subject_codes[1] = 4330702;
$subject_codes[2] = 4330703;
$subject_codes[3] = 4330704;
Another way to access all elements in the array using for loops is as below:
49 | P a g e
Introduction to Web Development (4340704)
Associative arrays
Associative arrays are similar to indexed arrays but instead of integer indexes values are
assigned to user-defined keys of string type. Below example shows how to assign
associative array:
$subjects = array("4330701" => "SLP",
"4330702" => "RDBMS",
"4330703" => "BOS",
"4330704" => "DSA");
50 | P a g e
Introduction to Web Development (4340704)
Multidimensional arrays
A multidimensional array is an array containing one or more arrays. PHP supports
multidimensional array that are two or more levels deep. However, arrays more than
three levels are hard to manage. Below is example of two dimensional array:
$subjects = array (
array("4330701","SLP",150),
array("4330702","RDBMS",150),
array("4330703","BOS",150),
array("4330704","DSA",150)
);
Below example shows a way to access all elements in the multidimensional array using
for loops is as below:
$subjects = array (
array("4330701","SLP",150),
array("4330702","RDBMS",150),
array("4330703","BOS",150),
array("4330704","DSA",150)
);
Resources Required:
Sr.
Instrument /Components Configuration/Specification
No
Processor:
1. Computer System RAM:
Operating System:
51 | P a g e
Introduction to Web Development (4340704)
Source Code:
Output:
52 | P a g e
Introduction to Web Development (4340704)
Output:
53 | P a g e
Introduction to Web Development (4340704)
Output:
54 | P a g e
Introduction to Web Development (4340704)
55 | P a g e
Introduction to Web Development (4340704)
Output:
56 | P a g e
Introduction to Web Development (4340704)
A. 4
B. 3
C. 2
D. 1
Which of the following array functions in PHP is used to sort an array in descending
order according to its values?
A) sort()
B) rsort()
C) asort()
D) arsort()
What is the output of the following code?
$arr1 = array(1, 2, 3);
$arr2 = array(4, 5, 6);
$result = array_merge($arr1, $arr2);
print_r($result);
A) Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 )
B) Array ( [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 )
C) Array ( [0] => 1 [1] => 4 [2] => 5 [3] => 6 )
D) None of the above
What is an associative array in PHP?
A) An array that stores values in indexed format
B) An array that stores values in a key-value pair format
C) An array that stores values in a multidimensional format
D) An array that stores values in a stack formatWhich of the following array
functions in PHP is used to remove the last element from an array?
A) array_pop()
B) array_shift()
C) array_slice()
D) array_splice()
Which of the following array functions in PHP is used to check whether a particular
value exists in an array or not?
A) in_array()
B) array_search()
C) array_key_exists()
57 | P a g e
Introduction to Web Development (4340704)
D) array_unique()
Which of the following array functions in PHP is used to remove the first element
from an array?
A) array_pop()
B) array_shift()
C) array_slice()
D) array_splice()
How to check if a key exists in an associative array in PHP?
A) Using the in_array() function
B) Using the array_search() function
C) Using the isset() function
D) Using the empty() function
Which of the following functions can be used to merge two or more arrays into one
array in PHP?
A) array_concat()
B) array_merge()
C) array_combine()
D) array_intersect()
What is the output of the following code?
$arr1 = array(1, 2, 3);
$arr2 = array(4, 5, 6);
$arr3 = $arr1 + $arr2;
print_r($arr3);
A) Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 )
B) Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 5 [4] => 6 )
C) Array ( [0] => 4 [1] => 5 [2] => 6 [3] => 1 [4] => 2 [5] => 3 )
D) Error
References:
https://www.php.net/manual/en/language.types.array.php
https://www.w3schools.com/php/php_arrays.asp
https://www.geeksforgeeks.org/php-arrays
https://www.tutorialspoint.com/php/php_arrays.htm
https://www.freecodecamp.org/news/how-to-use-arrays-in-php/
58 | P a g e
Introduction to Web Development (4340704)
Assessment Rubrics:
% of
Criteria Rubrics Marks
point
Excellent (10-8 marks): Completed programs/scripts
correctly as per the requirements.
C1: Adequate (7-6 marks): Completed programs/scripts
Program correctly with approx. 70% requirements.
50 %
Completeness/ Poor (5-4 marks): Completed programs/scripts correctly
Correctness with 70% - 50% requirements.
Unsatisfactory (0-3 marks): Completed programs/ scripts
correctly with less than 50% requirements.
Excellent (10-8 marks): The code is clean, well-organized and
very easy to understand.
Adequate (7-6 marks): The code is fairly easy to read and
C2: understand.
25 %
Readability Poor (5-4 marks): The code is readable only by someone who
knows what it is supposed to be doing.
Unsatisfactory (0-3 marks): The code is poorly organized and
very difficult to understand.
Excellent (10-8 marks):
• Coding standards are followed in complete code while
naming variables/functions/ classes, explaining the
purpose of variables/ functions/classes.
• The Complete code is well-documented with comments
explaining the code.
Adequate (7-6 marks):
• Coding standards are followed in most of the code while
naming variables/functions/ classes, explaining the
C3:
purpose of variables/ functions/classes.
Coding
25 % • Most of the code is documented with comments
Standards/ explaining the code.
Documentation
Poor (5-4 marks):
• Coding standards are followed in very little code while
naming variables/functions/ classes, explaining the
purpose of variables/ functions/classes.
• Very little code is documented with comments
explaining the code.
Unsatisfactory (0-3 marks):
• Coding standards are not followed properly.
• Proper comments are not written explaining the code.
Total Marks for Practical = 0.5 * (Marks of C1) + 0.25 * (Marks of C2) + 0.25 * (Marks of C3)
59 | P a g e
Introduction to Web Development (4340704)
Objectives:
A function is a block of reusable code that is used to perform a specific action. Functions
provide below advantages:
• Reduce duplication of the code.
• Modularisation of the code.
• Improve clarity of the code.
• Information hiding.
This practical will help student to practice writing PHP scripts using user defined
functions and in-built functions.
60 | P a g e
Introduction to Web Development (4340704)
Practical Outcomes:
Develop PHP scripts using in-built and user defined functions.
Prerequisite Theory:
A function is a block of code written in a program to perform some specific task.
Functions take inputs as parameters, executes a block of statements or perform
operations on these parameters and returns the result. There are two types of functions
in PHP:
• Built-in functions: PHP provides large collection of built-in library functions (more
than 1000 functions). Whenever we need, we can just call these built-in functions
as per our requirements.
• User defined functions: PHP allows us to create our own customised functions
called user defined functions. We can create our own packages of code and use
them whenever required.
User defined functions:
User defined functions are defined as below:
function functionname() {
Block of code;
}
Note: A function name must start with a letter or an underscore. Function names are
NOT case-sensitive.
Below code is example of PHP function which prints a message on the browser.
61 | P a g e
Introduction to Web Development (4340704)
<?php
function writeMessage() {
echo "Welcome to the PHP course..!!";
}
<?php
function printSubjects($code, $subject) {
echo "Subject name for code $code is $subject <br>";
}
Arguments are by default passed by value, which means that a copy of the value is
passed to the function, so the original variable that was passed into the function is not
changed when we modify argument in the function. We can pass argument by
reference, where changes made to the argument also change the original variable that
was passed in. The & operator is used to pass variable by reference in argument. Below
example show how to pass argument by reference:
<?php
function incrementVar(&$var) {
$var += 1;
return $var;
}
$a = 5;
$res = incrementVar($a);
echo "Value after increment is $res <br>";
?>
62 | P a g e
Introduction to Web Development (4340704)
<?php
function areaofCircle($radius = 10) {
$area = 2 * 3.14 * $radius;
echo "Area of Circle is : $area <br>";
}
areaofCircle();
areaofCircle(20);
?>
<?php
function sumArray($arr) {
$sum = 0;
for ($i = 0; $i < count($arr); $i++) {
$sum += $arr[$i];
}
return $sum;
}
$a = array(4, 9, 11, 25, 17);
$s = sumArray($a);
Resources Required:
Sr.
Instrument /Components Configuration/Specification
No
Processor:
1. Computer System RAM:
Operating System:
XAMPP Version:
2. XAMPP server
Editor:
3. Text Editor
63 | P a g e
Introduction to Web Development (4340704)
Output:
64 | P a g e
Introduction to Web Development (4340704)
65 | P a g e
Introduction to Web Development (4340704)
Output:
66 | P a g e
Introduction to Web Development (4340704)
Output:
Write a script to display the current date and time in different formats.
Source Code:
67 | P a g e
Introduction to Web Development (4340704)
Output:
68 | P a g e
Introduction to Web Development (4340704)
function test() {
$args = func_get_args();
foreach($args as $arg) {
echo $arg . " ";
}
}
test("hello", "world");
A) "hello world"
B) "hello, world"
C) "helloworld"
D) None of the above
Which function is used to check whether a function exists or not in PHP?
A) function_exists()
B) method_exists()
C) class_exists()
D) property_exists()
What is the output of the following code?
function myFunction(&$a) {
$a++;
}
$x = 5;
myFunction($x);
echo $x;
A. 5
B. 6
C. Error
D. None of the above
References:
https://www.php.net/manual/en/language.functions.php
https://www.w3schools.com/php/php_functions.asp
https://www.geeksforgeeks.org/php-functions
https://www.tutorialspoint.com/php/php_functions.htm
https://zetcode.com/php/function
69 | P a g e
Introduction to Web Development (4340704)
Assessment Rubrics:
% of
Criteria Rubrics Marks
point
Excellent (10-8 marks): Completed programs/scripts
correctly as per the requirements.
C1: Adequate (7-6 marks): Completed programs/scripts
Program correctly with approx. 70% requirements.
50 %
Completeness/ Poor (5-4 marks): Completed programs/scripts correctly
Correctness with 70% - 50% requirements.
Unsatisfactory (0-3 marks): Completed programs/ scripts
correctly with less than 50% requirements.
Excellent (10-8 marks): The code is clean, well-organized and
very easy to understand.
Adequate (7-6 marks): The code is fairly easy to read and
C2: understand.
25 %
Readability Poor (5-4 marks): The code is readable only by someone who
knows what it is supposed to be doing.
Unsatisfactory (0-3 marks): The code is poorly organized and
very difficult to understand.
Excellent (10-8 marks):
• Coding standards are followed in complete code while
naming variables/functions/ classes, explaining the
purpose of variables/ functions/classes.
• The Complete code is well-documented with comments
explaining the code.
Adequate (7-6 marks):
• Coding standards are followed in most of the code while
naming variables/functions/ classes, explaining the
C3:
purpose of variables/ functions/classes.
Coding
25 % • Most of the code is documented with comments
Standards/ explaining the code.
Documentation
Poor (5-4 marks):
• Coding standards are followed in very little code while
naming variables/functions/ classes, explaining the
purpose of variables/ functions/classes.
• Very little code is documented with comments
explaining the code.
Unsatisfactory (0-3 marks):
• Coding standards are not followed properly.
• Proper comments are not written explaining the code.
Total Marks for Practical = 0.5 * (Marks of C1) + 0.25 * (Marks of C2) + 0.25 * (Marks of C3)
70 | P a g e
Introduction to Web Development (4340704)
Objectives:
From PHP5, you can also write PHP code in an object-oriented style. Object-Oriented
Programming (OOP) is a programming paradigm that emphasizes the use of objects and
classes to structure code and data in a way that promotes code reuse, modularity, and
maintainability. In PHP, OOP has several practical significances, including:
• Code organization
• Encapsulation
• Inheritance
• Polymorphism
• Modularity
Overall, OOP in PHP can make it easier to write more maintainable, extensible, and
reliable code, which can ultimately lead to faster development times and fewer bugs.
71 | P a g e
Introduction to Web Development (4340704)
Practical Outcomes:
Develop PHP scripts with the help of various object-oriented concepts like class,
object, constructor, inheritance, interface, overloading and overriding.
Prerequisite Theory:
Before diving into implementing OOP concepts in PHP, it's important to have a solid
understanding of the following concepts:
• Classes and Objects: A class is a blueprint for creating objects, while an object is
an instance of a class. Classes define the properties and methods that objects will
have.
• Inheritance: Inheritance is a mechanism that allows a new class to be based on
an existing class, inheriting its properties and methods. This allows for code reuse
and can make it easier to organize your code.
• Encapsulation: Encapsulation is the practice of hiding the implementation details
of a class from the outside world, so that the class can only be accessed through
its public interface. This helps to prevent unintended changes to the state of an
object.
72 | P a g e
Introduction to Web Development (4340704)
Resources Required:
Sr.
Instrument /Components Configuration/Specification
No
Processor:
1. Computer System RAM:
Operating System:
Source code:
Write a script to define a class with constructor and destructor.
Source Code:
73 | P a g e
Introduction to Web Development (4340704)
Output:
74 | P a g e
Introduction to Web Development (4340704)
Create an object of a class and access its public properties and methods.
Source Code:
Output:
75 | P a g e
Introduction to Web Development (4340704)
Write a script that uses the set attribute and get attribute methods to access a
class’s private attributes of a class.
Source Code:
Output:
76 | P a g e
Introduction to Web Development (4340704)
Output:
77 | P a g e
Introduction to Web Development (4340704)
Output:
78 | P a g e
Introduction to Web Development (4340704)
Output:
79 | P a g e
Introduction to Web Development (4340704)
Output:
80 | P a g e
Introduction to Web Development (4340704)
Output:
81 | P a g e
Introduction to Web Development (4340704)
Output:
82 | P a g e
Introduction to Web Development (4340704)
Output:
83 | P a g e
Introduction to Web Development (4340704)
Output:
84 | P a g e
Introduction to Web Development (4340704)
85 | P a g e
Introduction to Web Development (4340704)
References:
https://www.w3schools.com/php/php_oop_intro.asp
https://code.tutsplus.com/tutorials/object-oriented-php-for-beginners--net-
12762
https://www.sitepoint.com/object-oriented-php-basics/
https://www.geeksforgeeks.org/object-oriented-programming-concepts-in-php/
https://www.php.net/manual/en/language.oop5.php
https://www.tutorialspoint.com/php/php_object_oriented.htm
86 | P a g e
Introduction to Web Development (4340704)
Assessment Rubrics:
% of
Criteria Rubrics Marks
point
Excellent (10-8 marks): Completed programs/scripts
correctly as per the requirements.
C1: Adequate (7-6 marks): Completed programs/scripts
Program correctly with approx. 70% requirements.
50 %
Completeness/ Poor (5-4 marks): Completed programs/scripts correctly
Correctness with 70% - 50% requirements.
Unsatisfactory (0-3 marks): Completed programs/ scripts
correctly with less than 50% requirements.
Excellent (10-8 marks): The code is clean, well-organized and
very easy to understand.
Adequate (7-6 marks): The code is fairly easy to read and
C2: understand.
25 %
Readability Poor (5-4 marks): The code is readable only by someone who
knows what it is supposed to be doing.
Unsatisfactory (0-3 marks): The code is poorly organized and
very difficult to understand.
Excellent (10-8 marks):
• Coding standards are followed in complete code while
naming variables/functions/ classes, explaining the
purpose of variables/ functions/classes.
• The Complete code is well-documented with comments
explaining the code.
Adequate (7-6 marks):
• Coding standards are followed in most of the code while
naming variables/functions/ classes, explaining the
C3:
purpose of variables/ functions/classes.
Coding
25 % • Most of the code is documented with comments
Standards/ explaining the code.
Documentation
Poor (5-4 marks):
• Coding standards are followed in very little code while
naming variables/functions/ classes, explaining the
purpose of variables/ functions/classes.
• Very little code is documented with comments
explaining the code.
Unsatisfactory (0-3 marks):
• Coding standards are not followed properly.
• Proper comments are not written explaining the code.
Total Marks for Practical = 0.5 * (Marks of C1) + 0.25 * (Marks of C2) + 0.25 * (Marks of C3)
87 | P a g e
Introduction to Web Development (4340704)
Objectives:
In PHP, forms are a powerful tool for collecting data from users and processing that data
on the server side. Here are some practical significances of using forms in PHP:
User Input: Forms allow users to enter information or data that can be processed
by PHP scripts on the server. This can include simple text input, file uploads, or even
complex data such as dates or email addresses.
Data Validation: Forms can be used to ensure that the data entered by users is valid
and meets certain criteria. For example, a form can check that an email address is
formatted correctly or that a password meets certain complexity requirements.
Security: Forms can be used to improve the security of PHP applications. For
example, forms can be used to implement measures such as CAPTCHA to prevent
automated attacks or CSRF tokens to prevent cross-site request forgery attacks.
User Experience: Forms can help to improve the user experience of PHP
applications by allowing users to interact with the application in a more intuitive
way. For example, forms can be used to allow users to search for specific content
or to create new accounts.
Data Processing: Forms allow PHP scripts to process user data on the server side.
This can include saving data to a database, sending email notifications, or
performing complex calculations.
Overall, forms are a fundamental part of PHP development and are an essential tool for
building interactive, user-friendly, and secure web applications.
88 | P a g e
Introduction to Web Development (4340704)
Practical Outcomes:
Create PHP scripts with the use of various form elements, perform validation and
implement form processing.
Prerequisite Theory:
Forms handling in PHP involves collecting data submitted by users through HTML
forms, processing that data using PHP scripts, and then taking actions based on that
data. Here are the steps involved in forms handling in PHP:
Creating an HTML form: First, create an HTML form that users can fill out. This form
should include input fields like text boxes, radio buttons, and checkboxes, and it
should have a "submit" button that sends the data to a PHP script.
Setting the "action" attribute: In the form tag, you should set the "action" attribute
to the filename of the PHP script that will process the data. When the user submits
the form, the data will be sent to this script for processing.
Retrieving form data: In the PHP script that will process the form data, you should
use the $_POST superglobal to retrieve the data submitted by the user. The $_POST
array contains key-value pairs, where the key is the name of the form field and the
value is the data entered by the user.
89 | P a g e
Introduction to Web Development (4340704)
Validating form data: Before processing the form data, you should validate it to
ensure that it is in the correct format and that it contains the required data. You
can use PHP's built-in functions for data validation, or you can create custom
validation functions.
Sanitizing form data: After validating the form data, you should sanitize it to
prevent malicious input, such as SQL injection attacks. You can use PHP's built-in
functions for data sanitization, such as htmlspecialchars() or filter_var().
Processing form data: Once the form data has been validated and sanitized, you
can process it according to your application's requirements. For example, you might
insert the data into a database, send an email, or redirect the user to a different
page.
Displaying feedback: After the form data has been processed, you should provide
feedback to the user. This might include a message confirming that their data was
successfully submitted or an error message if the data could not be processed.
In summary, forms handling in PHP involves creating an HTML form, processing the
data submitted through the form using a PHP script, validating and sanitizing the data,
and then taking actions based on that data. By following these steps, you can create
robust and secure web applications that can handle a wide range of user inputs.
Example HTML Form:
<!DOCTYPE html>
<html>
<head>
<title>Registration Form</title>
</head>
<body>
<h2>Registration Form</h2>
<form action="register.php" method="post">
<label for="username">Username:</label>
<input type="text" name="username" id="username"><br>
<label for="email">Email:</label>
<input type="email" name="email" id="email"><br>
90 | P a g e
Introduction to Web Development (4340704)
The form has three input fields for the user to enter their desired username, email, and
password. The form's action attribute is set to register.php, which is the PHP script that
will handle the form data. The method attribute is set to post, indicating that the form
data will be sent as a POST request.
PHP Script (register.php):
<?php
// Retrieve form data
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
The PHP script retrieves the form data using the $_POST superglobal and then validates
and sanitizes the data to prevent malicious input. In this example, the script checks that
all fields are filled in and uses the htmlspecialchars() and filter_var() functions to sanitize
the data.
Finally, the script processes the form data by displaying it back to the user. In a real-
world scenario, you might store the form data in a database or send it in an email.
That's it! This is a simple example of a registration page in PHP.
91 | P a g e
Introduction to Web Development (4340704)
Resources Required:
Sr.
Instrument /Components Configuration/Specification
No
Processor:
1. Computer System RAM:
Operating System:
92 | P a g e
Introduction to Web Development (4340704)
Output:
Create two distinct web pages to demonstrate information passing between them
using URL - Get method.
Source Code:
93 | P a g e
Introduction to Web Development (4340704)
Output:
Create two different web pages to demonstrate information passing between web
pages using Hidden variables - Post method.
Source Code:
94 | P a g e
Introduction to Web Development (4340704)
Output:
95 | P a g e
Introduction to Web Development (4340704)
References:
https://www.w3schools.com/php/php_forms.asp
https://www.geeksforgeeks.org/php-form-handling/
https://www.tutorialspoint.com/php/php_forms.htm
https://www.php.net/manual/en/tutorial.forms.php
https://www.tutorialrepublic.com/php-tutorial/php-form-validation.php
96 | P a g e
Introduction to Web Development (4340704)
Assessment Rubrics:
% of
Criteria Rubrics Marks
point
Excellent (10-8 marks): Completed programs/scripts
correctly as per the requirements.
C1: Adequate (7-6 marks): Completed programs/scripts
Program correctly with approx. 70% requirements.
50 %
Completeness/ Poor (5-4 marks): Completed programs/scripts correctly
Correctness with 70% - 50% requirements.
Unsatisfactory (0-3 marks): Completed programs/ scripts
correctly with less than 50% requirements.
Excellent (10-8 marks): The code is clean, well-organized and
very easy to understand.
Adequate (7-6 marks): The code is fairly easy to read and
C2: understand.
25 %
Readability Poor (5-4 marks): The code is readable only by someone who
knows what it is supposed to be doing.
Unsatisfactory (0-3 marks): The code is poorly organized and
very difficult to understand.
Excellent (10-8 marks):
• Coding standards are followed in complete code while
naming variables/functions/ classes, explaining the
purpose of variables/ functions/classes.
• The Complete code is well-documented with comments
explaining the code.
Adequate (7-6 marks):
• Coding standards are followed in most of the code while
naming variables/functions/ classes, explaining the
C3:
purpose of variables/ functions/classes.
Coding
25 % • Most of the code is documented with comments
Standards/ explaining the code.
Documentation
Poor (5-4 marks):
• Coding standards are followed in very little code while
naming variables/functions/ classes, explaining the
purpose of variables/ functions/classes.
• Very little code is documented with comments
explaining the code.
Unsatisfactory (0-3 marks):
• Coding standards are not followed properly.
• Proper comments are not written explaining the code.
Total Marks for Practical = 0.5 * (Marks of C1) + 0.25 * (Marks of C2) + 0.25 * (Marks of C3)
97 | P a g e
Introduction to Web Development (4340704)
Objectives:
Sessions and cookies are important concepts in web development, and they have
practical significance in PHP in several ways:
User authentication: Sessions and cookies can be used to authenticate users on a
website. When a user logs in, their session ID can be stored in a cookie, and the
server can verify the ID to ensure that the user is authorized to access certain pages
or features.
Personalization: Sessions and cookies can be used to personalize the user
experience on a website. For example, a session can be used to store the user's
preferred language or theme, and a cookie can be used to remember the user's
login credentials for future visits.
Shopping carts: Sessions and cookies can be used to create and manage shopping
carts on an e-commerce website. The contents of the user's cart can be stored in a
session, and a cookie can be used to remember the user's cart across multiple visits.
Tracking user behaviour: Cookies can be used to track user behaviour on a website,
such as which pages they visit and which links they click. This information can be
used to improve the website's usability and performance.
Security: Sessions and cookies can be used to enhance the security of a website.
For example, a session can be used to prevent CSRF (cross-site request forgery)
attacks, while cookies can be used to prevent XSS (cross-site scripting) attacks.
98 | P a g e
Introduction to Web Development (4340704)
Life-long learning (PO7): Ability to analyse individual needs and engage in updating
in the context of technological changes in field of engineering.
Practical Outcomes:
Implement session and cookie to store and manage user data.
Prerequisite Theory:
In PHP, sessions and cookies are two mechanisms used to store and manage data
related to a user's interaction with a website or web application.
SESSION
Sessions are a way of storing information on the server about a user's activity on a
website. When a user visits a website, the server assigns them a unique session ID,
which is stored in a cookie on the user's computer. The server then uses this session ID
to keep track of the user's activity as they move around the website. The session data
can include things like user preferences, shopping cart items, or authentication status.
Sessions can be started using the session_start() function and the session data can be
accessed through the $_SESSION superglobal array.
COOKIE
Cookies are small text files that are stored on a user's computer by their web browser.
Cookies are often used to remember user preferences or login information, or to track
user behavior across different pages or sessions. In PHP, cookies can be set using the
setcookie() function. Cookies can have an expiration time, after which they are
automatically deleted, or they can be set to expire when the user closes their browser.
Cookie data can be accessed using the $_COOKIE superglobal array.
COMPARISION
Both sessions and cookies have their advantages and disadvantages. Sessions are
generally more secure because the data is stored on the server, but they can be
99 | P a g e
Introduction to Web Development (4340704)
slower and less flexible. Cookies are faster and more flexible, but they can be less
secure because the data is stored on the user's computer. When using cookies, it's
important to make sure that sensitive information, such as passwords or credit card
numbers, is not stored in the cookie.
In summary, sessions and cookies are two important mechanisms used to store and
manage user-related data in PHP. By understanding how to use these mechanisms
correctly, developers can create more secure and user-friendly web applications.
Examples
Using Session
Start the session using the session_start() function.
<?php
session_start();
>
Using Cookie
1. Set a cookie using the setcookie() function.
<?php
$cookie_name "username";
$cookie_value = "Ashish";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");
?>
100 | P a g e
Introduction to Web Development (4340704)
Note that when using sessions and cookies, it's important to be careful about what
data is stored and how it's accessed, to prevent security issues. For example, sensitive
information like passwords or credit card numbers should never be stored in a cookie
or session.
Resources Required:
Sr.
Instrument /Components Configuration/Specification
No
Processor:
1. Computer System RAM:
Operating System:
101 | P a g e
Introduction to Web Development (4340704)
Output:
102 | P a g e
Introduction to Web Development (4340704)
Output:
103 | P a g e
Introduction to Web Development (4340704)
104 | P a g e
Introduction to Web Development (4340704)
A) Sessions
B) Cookies
C) They are equally secure
D) It depends on the use case
What kind of data should not be stored in a cookie?
A) User preferences
B) Login information
C) Sensitive information like passwords or credit card numbers
D) All of the above can be stored in a cookie
What superglobal array is used to access session data in PHP?
A) $_SESSION
B) $_COOKIE
C) $_REQUEST
D) $_SERVER
What superglobal array is used to access cookie data in PHP?
A) $_SESSION
B) $_COOKIE
C) $_REQUEST
D) $_SERVER
How can you delete a cookie in PHP?
A) By using the setcookie() function with an expiration time in the past
B) By using the unset() function with the cookie variable
C) By using the delete_cookie() function with the cookie name
D) Cookies cannot be deleted once they are set
References:
https://www.php.net/manual/en/features.sessions.php
https://www.php.net/manual/en/function.setcookie.php
https://www.tutorialspoint.com/php/php_sessions.htm
https://www.tutorialspoint.com/php/php_cookies.htm
https://www.w3schools.com/php/php_sessions.asp
https://www.w3schools.com/php/php_cookies.asp
https://www.geeksforgeeks.org/php-sessions/
https://www.geeksforgeeks.org/php-cookies/
105 | P a g e
Introduction to Web Development (4340704)
Assessment Rubrics:
% of
Criteria Rubrics Marks
point
Excellent (10-8 marks): Completed programs/scripts
correctly as per the requirements.
C1: Adequate (7-6 marks): Completed programs/scripts
Program correctly with approx. 70% requirements.
50 %
Completeness/ Poor (5-4 marks): Completed programs/scripts correctly
Correctness with 70% - 50% requirements.
Unsatisfactory (0-3 marks): Completed programs/ scripts
correctly with less than 50% requirements.
Excellent (10-8 marks): The code is clean, well-organized and
very easy to understand.
Adequate (7-6 marks): The code is fairly easy to read and
C2: understand.
25 %
Readability Poor (5-4 marks): The code is readable only by someone who
knows what it is supposed to be doing.
Unsatisfactory (0-3 marks): The code is poorly organized and
very difficult to understand.
Excellent (10-8 marks):
• Coding standards are followed in complete code while
naming variables/functions/ classes, explaining the
purpose of variables/ functions/classes.
• The Complete code is well-documented with comments
explaining the code.
Adequate (7-6 marks):
• Coding standards are followed in most of the code while
naming variables/functions/ classes, explaining the
C3:
purpose of variables/ functions/classes.
Coding
25 % • Most of the code is documented with comments
Standards/ explaining the code.
Documentation
Poor (5-4 marks):
• Coding standards are followed in very little code while
naming variables/functions/ classes, explaining the
purpose of variables/ functions/classes.
• Very little code is documented with comments
explaining the code.
Unsatisfactory (0-3 marks):
• Coding standards are not followed properly.
• Proper comments are not written explaining the code.
Total Marks for Practical = 0.5 * (Marks of C1) + 0.25 * (Marks of C2) + 0.25 * (Marks of C3)
106 | P a g e
Introduction to Web Development (4340704)
Objectives:
Databases are an essential part of many web applications developed with PHP. Here are
some practical reasons why databases are important in PHP development:
Data storage: Databases provide a structured way to store and organize data for
PHP applications. This makes it easy to manage and retrieve data using SQL queries.
Scalability: Databases can handle large amounts of data and high traffic volumes,
making it a great choice for PHP applications that need to grow and scale over time.
Security: Databases provide strong security features to protect data and prevent
unauthorized access. This includes user authentication, data encryption, and role-
based access control.
Data analysis: Databases can be used to perform complex data analysis and
generate reports. This is useful for PHP applications that need to process large
amounts of data and extract meaningful insights.
Data synchronization: Databases can be used to synchronize data between
different systems and applications. This is useful for PHP applications that need to
integrate with other systems and exchange data in real-time.
Overall, databases are an essential tool for PHP developers, providing reliable data
storage, scalability, security, data analysis, and data synchronization. They play a crucial
role in many web applications, and their importance cannot be overstated.
107 | P a g e
Introduction to Web Development (4340704)
Practical Outcomes:
Implement various database operations using PHP script.
Prerequisite Theory:
MySQL is a popular relational database management system that is commonly used in
web development with PHP. Here are some MySQL functions that can be used in PHP
to interact with MySQL databases:
mysqli_connect() - This function is used to establish a connection to a MySQL
database server.
mysqli_query() - This function is used to execute a MySQL query on a connected
database.
mysqli_fetch_array() - This function is used to fetch the result of a MySQL query as
an array.
mysqli_insert_id() - This function is used to get the auto-generated ID of the last
inserted record in a table.
mysqli_real_escape_string() - This function is used to escape special characters in
a string to prevent SQL injection attacks.
108 | P a g e
Introduction to Web Development (4340704)
<?php
$host = "localhost"; $username = "db_user";
$password = "db_password";
$dbname = "my_database";
// Create connection
$conn = mysqli_connect($host, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: mysqli_connect_error());
}
echo "Connected successfully";
?>
109 | P a g e
Introduction to Web Development (4340704)
<?php
$username = "john_doe";
$password = "my_password";
<?php
// Create and execute the SQL query to retrieve all users
$sql = "SELECT * FROM users";
$result = mysqli_query($conn, $sql);
110 | P a g e
Introduction to Web Development (4340704)
<?php
$username "ashish";
$new_password = "new_password";
// Create and execute the SQL query to update the password for a
// specific user
$sql = "UPDATE users SET password='$new_password' WHERE
username='$username'
if (mysqli_query($conn, $sql)) {
echo "Record updated successfully";
}
else {
echo "Error updating record: mysqli_error($conn);
}
?>
<?php
$username "ashish";
111 | P a g e
Introduction to Web Development (4340704)
Resources Required:
Sr.
Instrument /Components Configuration/Specification
No
Processor:
1. Computer System RAM:
Operating System:
112 | P a g e
Introduction to Web Development (4340704)
Output:
113 | P a g e
Introduction to Web Development (4340704)
Output:
114 | P a g e
Introduction to Web Development (4340704)
Output:
After an employee log in, create a home web page that displays basic employee
information.
Source Code:
115 | P a g e
Introduction to Web Development (4340704)
Output:
116 | P a g e
Introduction to Web Development (4340704)
Output:
117 | P a g e
Introduction to Web Development (4340704)
Output:
A) mysqli_stmt_execute()
B) mysqli_execute_stmt()
C) mysqli_stmt_query()
D) None of the above
Which of the following is used to retrieve the result set of a query executed with
mysqli?
A) mysqli_fetch_row()
B) mysqli_fetch_array()
C) mysqli_fetch_assoc()
D) All of the above
What is the function used to close a connection to a MySQL database with mysqli?
A) mysqli_close()
B) mysqli_disconnect()
C) mysqli_terminate()
D) None of the above
Which of the following is used to retrieve the number of rows affected by a query
executed with mysqli?
A) mysqli_affected_rows()
B) mysqli_num_rows()
C) Both A and B
D) None of the above
Which of the following methods is used to check for errors in a MySQLi database
query in PHP?
A) mysqli_errno()
B) mysqli_error()
C) mysqli_connect_errno()
D) All of the above
References:
https://www.php.net/manual/en/book.mysql.php
https://www.w3schools.com/php/php_mysql_intro.asp
https://www.tutorialspoint.com/php/php_mysql.htm
https://phpdelusions.net/mysqli
https://www.geeksforgeeks.org/mysqli-procedural-functions
https://www.guru99.com/mysql-php-and-other-database-access-methods.html
119 | P a g e
Introduction to Web Development (4340704)
Assessment Rubrics:
% of
Criteria Rubrics Marks
point
Excellent (10-8 marks): Completed programs/scripts
correctly as per the requirements.
C1: Adequate (7-6 marks): Completed programs/scripts
Program correctly with approx. 70% requirements.
50 %
Completeness/ Poor (5-4 marks): Completed programs/scripts correctly
Correctness with 70% - 50% requirements.
Unsatisfactory (0-3 marks): Completed programs/ scripts
correctly with less than 50% requirements.
Excellent (10-8 marks): The code is clean, well-organized and
very easy to understand.
Adequate (7-6 marks): The code is fairly easy to read and
C2: understand.
25 %
Readability Poor (5-4 marks): The code is readable only by someone who
knows what it is supposed to be doing.
Unsatisfactory (0-3 marks): The code is poorly organized and
very difficult to understand.
Excellent (10-8 marks):
• Coding standards are followed in complete code while
naming variables/functions/ classes, explaining the
purpose of variables/ functions/classes.
• The Complete code is well-documented with comments
explaining the code.
Adequate (7-6 marks):
• Coding standards are followed in most of the code while
naming variables/functions/ classes, explaining the
C3:
purpose of variables/ functions/classes.
Coding
25 % • Most of the code is documented with comments
Standards/ explaining the code.
Documentation
Poor (5-4 marks):
• Coding standards are followed in very little code while
naming variables/functions/ classes, explaining the
purpose of variables/ functions/classes.
• Very little code is documented with comments
explaining the code.
Unsatisfactory (0-3 marks):
• Coding standards are not followed properly.
• Proper comments are not written explaining the code.
Total Marks for Practical = 0.5 * (Marks of C1) + 0.25 * (Marks of C2) + 0.25 * (Marks of C3)
120 | P a g e
Introduction to Web Development (4340704)
Objectives:
Email, PDF, and JSON are three distinct types of data formats that can be used in PHP
for various practical purposes.
Email: PHP provides built-in email functions that allow developers to send and
receive emails using different protocols such as SMTP, IMAP, and POP3. Email is
widely used for communication purposes in various web applications, such as
sending verification emails, password reset links, newsletters, and order
confirmations.
PDF: PDF is a popular file format used for creating and sharing documents that can
be viewed on different devices and platforms. PHP provides various libraries and
tools for generating and manipulating PDF documents, such as FPDF, TCPDF, and
mPDF. PDFs are often used for generating invoices, receipts, reports, and other
types of documents in web applications.
JSON: JSON (JavaScript Object Notation) is a lightweight data interchange format
that is easy to read and write for humans and machines. JSON is often used for
exchanging data between client-side and server-side applications using AJAX
(Asynchronous JavaScript and XML) and RESTful (Representational State Transfer)
APIs. PHP provides built-in functions for encoding and decoding JSON data, such as
json_encode() and json_decode().
121 | P a g e
Introduction to Web Development (4340704)
Life-long learning (PO7): Ability to analyse individual needs and engage in updating
in the context of technological changes in field of engineering.
Practical Outcomes:
Implement Email, PDF and JSON facility for data exchange and document
generation using PHP script.
Prerequisite Theory:
Email
Email is a common communication tool used in web development, and PHP provides
built-in functions and libraries to send and receive emails. Here are the basic steps to
send an email in PHP.
• Configure the SMTP server settings
• Set up the email headers
• Compose the email message
Example
$to = '[email protected]';
$subject = 'Test email';
$message = 'Hello, this is a test email!';
122 | P a g e
Introduction to Web Development (4340704)
PDF
PDF (Portable Document Format) is a commonly used document format that allows for
easy sharing and printing of documents. PHP provides several libraries and functions
that allow for the creation and manipulation of PDF documents. Here are the basic steps
to create a PDF document in PHP:
• Install a PDF library: There are several PDF libraries available for PHP, such as FPDF,
TCPDF, and DOMPDF. You need to install and configure a PDF library to generate the
PDF document.
• Create a PDF object: Once you have installed a PDF library, you can create a PDF
object to represent the document. This object contains methods and properties for
adding content to the PDF document, such as text, images, tables, and other
elements.
• Add content to the PDF document: You can use the methods provided by the PDF
library to add content to the PDF document. For example, you can use the SetFont()
method to set the font style, Cell() method to add text to the document, and Image()
method to add images to the document.
• Output the PDF document: Once you have added all the content to the PDF
document, you can output the document to the browser or save it to a file. The PDF
library provides methods to output the PDF document in various formats, such as
PDF, HTML, or image.
Here is an example code snippet to create a PDF document using the FPDF library in
PHP:
<?php
require('fpdf/fpdf.php');
JSON
JSON (JavaScript Object Notation) is a lightweight data interchange format that is
commonly used for exchanging data between web applications. PHP provides several
built-in functions and libraries to encode and decode JSON data. Here are the basic
steps to work with JSON data in PHP:
Encode PHP data into JSON format: To encode PHP data into JSON format, you can use
the json_encode() function. This function converts a PHP object or array into a JSON
string.
123 | P a g e
Introduction to Web Development (4340704)
$person = array(
"name" => "John",
"age" => 30,
"city" => "New York"
);
$json = json_encode($person);
echo $json;
In this example, we have defined a PHP array person and encoded it into a JSON string
using the json_encode() function. The output of the code will be:
{"name":"John","age":30,"city":"New York"}
Resources Required:
Sr.
Instrument /Components Configuration/Specification
No
Processor:
1. Computer System RAM:
Operating System:
124 | P a g e
Introduction to Web Development (4340704)
Output:
125 | P a g e
Introduction to Web Development (4340704)
Output:
126 | P a g e
Introduction to Web Development (4340704)
Write a script to convert an associative array into JSON string format and vice versa.
Source Code:
Output:
127 | P a g e
Introduction to Web Development (4340704)
128 | P a g e
Introduction to Web Development (4340704)
A) AddImage()
B) Image()
C) InsertImage()
D) None of the above
Which PHP library has better support for HTML to PDF conversion?
A) FPDF
B) TCPDF
C) Dompdf
D) None of the above
Which PHP function is used to encode a PHP array or object into a JSON string?
A) json_encode()
B) json_decode()
C) json_parse()
D) None of the above
Which PHP function can be used to decode a JSON string into a PHP object or array?
A) json_encode()
B) json_decode()
C) serialize()
D) unserialize()
Which of the following PHP functions can be used to check if a JSON string is valid?
A) json_encode()
B) json_decode()
C) json_last_error()
D) None of the above
References:
https://www.php.net/manual/en/function.mail.php
https://www.tutorialspoint.com/php/php_sending_emails.htm
https://www.sitepoint.com/generate-pdfs-php/
https://www.geeksforgeeks.org/how-to-generate-pdf-file-using-php/
https://www.php.net/manual/en/function.json-encode.php
https://www.w3schools.com/js/js_json_php.asp
129 | P a g e
Introduction to Web Development (4340704)
Assessment Rubrics:
% of
Criteria Rubrics Marks
point
Excellent (10-8 marks): Completed programs/scripts
correctly as per the requirements.
C1: Adequate (7-6 marks): Completed programs/scripts
Program correctly with approx. 70% requirements.
50 %
Completeness/ Poor (5-4 marks): Completed programs/scripts correctly
Correctness with 70% - 50% requirements.
Unsatisfactory (0-3 marks): Completed programs/ scripts
correctly with less than 50% requirements.
Excellent (10-8 marks): The code is clean, well-organized and
very easy to understand.
Adequate (7-6 marks): The code is fairly easy to read and
C2: understand.
25 %
Readability Poor (5-4 marks): The code is readable only by someone who
knows what it is supposed to be doing.
Unsatisfactory (0-3 marks): The code is poorly organized and
very difficult to understand.
Excellent (10-8 marks):
• Coding standards are followed in complete code while
naming variables/functions/ classes, explaining the
purpose of variables/ functions/classes.
• The Complete code is well-documented with comments
explaining the code.
Adequate (7-6 marks):
• Coding standards are followed in most of the code while
naming variables/functions/ classes, explaining the
C3:
purpose of variables/ functions/classes.
Coding
25 % • Most of the code is documented with comments
Standards/ explaining the code.
Documentation
Poor (5-4 marks):
• Coding standards are followed in very little code while
naming variables/functions/ classes, explaining the
purpose of variables/ functions/classes.
• Very little code is documented with comments
explaining the code.
Unsatisfactory (0-3 marks):
• Coding standards are not followed properly.
• Proper comments are not written explaining the code.
Total Marks for Practical = 0.5 * (Marks of C1) + 0.25 * (Marks of C2) + 0.25 * (Marks of C3)
130 | P a g e
Introduction to Web Development (4340704)
Objectives:
Development of simple web application as mini-project will give an experience of
problem-solving along with group members, by using knowledge and under the
guidance of a faculty. Mini-project will help students to develop different skills such as:
team work, researching on a topic, problem solving, time management, planning, code
development, testing and documentation.
131 | P a g e
Introduction to Web Development (4340704)
Develop web pages using form controls with validation to collect user inputs in PHP.
Develop and host interactive websites using PHP and MySQL database.
Practical Outcomes:
Develop simple application using PHP and MySQL.
Resources Required:
Sr.
Instrument /Components Configuration/Specification
No
Processor:
1. Computer System RAM:
Operating System:
132 | P a g e
Introduction to Web Development (4340704)
133 | P a g e
Introduction to Web Development (4340704)
134 | P a g e
Introduction to Web Development (4340704)
Output:
135 | P a g e
Introduction to Web Development (4340704)
Assessment Rubrics:
% of
Criteria Rubrics Marks
point
Excellent (10-8 marks): Completed project/scripts correctly
as per the requirements.
C1: Adequate (7-6 marks): Completed project /scripts correctly
Project with approx. 70% requirements.
50 %
Completeness/ Poor (5-4 marks): Completed project /scripts correctly with
Correctness 70% - 50% requirements.
Unsatisfactory (0-3 marks): Completed project/ scripts
correctly with less than 50% requirements.
Excellent (10-8 marks): The code is clean, well-organized and
very easy to understand.
Adequate (7-6 marks): The code is fairly easy to read and
C2: understand.
25 %
Readability Poor (5-4 marks): The code is readable only by someone who
knows what it is supposed to be doing.
Unsatisfactory (0-3 marks): The code is poorly organized and
very difficult to understand.
Excellent (10-8 marks):
• Coding standards are followed in complete code while
naming variables/functions/ classes, explaining the
purpose of variables/ functions/classes.
• The Complete code is well-documented with comments
explaining the code.
Adequate (7-6 marks):
• Coding standards are followed in most of the code while
naming variables/functions/ classes, explaining the
C3:
purpose of variables/ functions/classes.
Coding
25 % • Most of the code is documented with comments
Standards/ explaining the code.
Documentation
Poor (5-4 marks):
• Coding standards are followed in very little code while
naming variables/functions/ classes, explaining the
purpose of variables/ functions/classes.
• Very little code is documented with comments
explaining the code.
Unsatisfactory (0-3 marks):
• Coding standards are not followed properly.
• Proper comments are not written explaining the code.
Total Marks for Practical = 0.5 * (Marks of C1) + 0.25 * (Marks of C2) + 0.25 * (Marks of C3)
136 | P a g e