WBP Summer 2023 Model Answer Paper
WBP Summer 2023 Model Answer Paper
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619
Page 1 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619
5. User-friendly:
It has a less learning curve, and one can learn it quickly.
6. Flexible:
It is highly flexible, and people can readily use it to combine its function
with various other programming languages.
7. PHP uses its own memory space, so the workload of the server and
loading time reduces automatically, which results into the faster processing
speed.
8.PHP has multiple layers of security to prevent threats and malicious
attacks.
b) State the use of strlen() and strrev() 2M
Ans. Strlen(): Use of each
The strlen() function is used to count number of characters in a string. It method- 1M
returns the length of a string.
Strrev():
The strrev() function is used to reverse a string.
c) Define introspection 2M
Ans. Introspection is the ability of a program to examine object characteristics Correct
definition 2M
such as its name, parent class, properties and method.
d) Enlist the attributes of cookies. 2M
Ans. Attributes of Cookies are as follows: List any four
1. name attributes 1/2M
each
2. value
3. expire
4. path
5. domain
6. secure
e) Write syntax of constructing PHP webpage with MySQL 2M
Ans. Using MySQLi object-oriented procedure: Correct syntax
Syntax: 2M
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Creating connection
$conn = new mysqli($servername, $username, $password);
// Checking connection
Page 2 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
OR
POST method:
POST method is a way to pass data entered in form to the server securely
without adding it to URL.
OR
It Handles request in servlet which is sent by the client. If a client is entering
registration data in an html form, the data can be sent using post method.
Page 3 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619
Page 4 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619
Multidimensional Arrays
In multi-dimensional array, each element in the main array can also be an
array. A multidimensional array is an array containing one or more arrays. It
has more than one dimension in the form of rows and columns. Values in the
multi-dimensional array are accessed using multiple indexes. Example:
Page 5 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619
Page 6 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619
BCC is the acronym for blind carbon copy. It is similar to CC. The email
addresses included in the BCC section will not be shown to the other
recipients.
4. PHP mailer uses Simple Mail Transmission Protocol (SMTP) to send mail.
On a hosted server, the SMTP settings would have already been set. The
SMTP mail settings can be configured from “php.ini” & “sendemail.ini”
file in the PHP installation folder.
The first parameter of the implode The first parameter of the explode
function is optional. function is required.
Syntax: Syntax:
string implode(string $seperator, array explode(string
array $array) separator,string string)
Example: Example:
<?php <?php
$arr = array('CO','IF','EJ'); $str = "CO-IF-EJ";
$str = implode(" ",$arr); $arr = implode("-",$str);
echo $str; print_r($arr);
?> ?>
Page 7 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619
Example:
<?php
// Creating instance of Animals class
$objAnimals = new Animals();
// Assigning values
$objAnimals->name = "Lion";
$objAnimals->category = "Wild Animal";
// Cloning the original object
$objCloned = clone $objAnimals;
$objCloned->name = "Elephant";
$objCloned->category = "Wild Animal";
print_r($objAnimals);
print_r($objCloned);
?>
c) Describe the procedure of validation of web page 4M
Ans. Validating a web page in PHP involves checking the input data provided by
Explanation
users to ensure that it meets the required criteria and is safe for further 3M
processing. Here's a general procedure for validating a web page in PHP:
The procedure of validation of web page.
Define the Validation Rules: Determine the validation rules for each input Example 1M
field on the web page. This includes constraints such as required fields, data
formats (e.g., email, date), length limits, and any specific patterns or
restrictions.
Create the HTML Form: Design and create the HTML form that collects
user input. Specify the appropriate input types, such as text, email, number,
etc., and include any necessary attributes like required or pattern.
Page 8 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619
Submitting the Form: Set up the PHP script that processes the form
submission. This script will be responsible for handling the validation and
processing the data. Ensure that the form's method attribute is set to "POST"
so that the data is sent securely.
Retrieve and Sanitize Input: In the PHP script, retrieve the submitted data
using the $_POST superglobal array. Sanitize the input to remove any
unwanted characters or tags that could potentially pose security risks. You
can use functions like htmlspecialchars or filter_input to sanitize specific
inputs.
Display Validation Errors: If any input fails validation, store the error
messages in an array or variable. Display these error messages next to the
corresponding input fields on the web page, informing the user about the
specific validation issues they need to address.
Process Valid Data: If all the input data passes validation, proceed with
further processing, such as storing the data in a database, sending emails, or
performing other necessary operations.
Page 9 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 10 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619
if ($conn->connect_error) die($conn->connect_error);
$query = "DELETE from student WHERE rollno='CO103'";
$result = $conn->query($query);
if (!$result) die ("Database access failed: " . $conn->error);
?>
4. Attempt any THREE of the following: 12M
a) State user defined functions and explain it with example. 4M
Ans. A function is a named block of code that performs a specific task.PHP
supports user defined functions, where user can define his own functions. Correct
explanation -
A function doesn't execute when its defined, it executes when it is called.
2M
The syntax to create a PHP user defined function –
A PHP user-defined function declaration starts with the keyword function as
shown below – Any correct
function funName($arg1, $arg2, ... $argn) Example-2M
{
// code to be executed inside a function
//return $val
}
The syntax to call a PHP user-defined function –
$ret=funName($arg1, $arg2, ... $argn);
Example:
<?php
// user-defined function definition
function printMessage(){
echo "Hello, How are you?";
}
//user-defined function call
printMessage();
?>
As in the above program, the printMessage() function is created using the
keyword function. The function prints the message “Hello, How are you?”.
So, farther in the program when it is calling the function as
“printMessage();”. It prints a message, as we can see in the above output.
Page 11 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 12 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619
Explanation
3M
Page 13 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619
server can handle requests for static files like CSS, JavaScript, and images,
delivering them directly to the client without involving PHP processing. It
can also handle URL rewriting or redirection for search engine optimization
(SEO) purposes or to create user-friendly URLs.
5. Content Delivery: Once the PHP script execution is complete, the web
server sends the generated content (usually HTML) back to the client's
browser as an HTTP response. The server sets the appropriate headers, such
as Content-Type, Content-Length, and caching directives, to ensure the
correct interpretation and rendering of the response by the client.
6. Error Handling and Logging: The web server is responsible for handling
errors and logging relevant information. If an error occurs during PHP script
execution, the web server can be configured to display an error message or
redirect to a custom error page. It also logs information about requests, errors,
and server events, which can be helpful for debugging, monitoring, and
performance analysis.
<?php
require_once 'login.php';
$conn = new mysqli($hn, $un, $pw, $db);
if ($conn->connect_error) die($conn->connect_error);
$query = "INSERT INTO student(rollno,name,percent) VALUES
('CO103','Reena Patel',98.45)";
$result = $conn->query($query);
if (!$result) die ("Database access failed: " . $conn->error);
?>
Page 14 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619
Retrieving operation:
The data can be retrieved from the table using SQL SELECT statement which
is used to select the records from database tables.
SQL query using the SELECT statement will be executed by passing this
SQL query to the PHP query() function to retrieve the table data.
For example data from the student table can be executed by using the
SELECT statement.
select_sample.php
<?php
require_once 'login.php';
$conn = new mysqli($hn, $un, $pw, $db);
if ($conn->connect_error) die($conn->connect_error);
$query = "SELECT * FROM student";
$result = $conn->query($query);
if (!$result) die ("Database access failed: " .
$conn->error);
$rows = $result->num_rows;
echo "<table
border='1'><tr><th>RollNo.</th><th>Name</th><th>Percentage</th></tr>";
for ($j = 0 ; $j < $rows ; ++$j)
{
$result->data_seek($j);
$row = $result->fetch_array(MYSQLI_NUM);
echo "<tr>";
for ($k = 0 ; $k < 3 ; ++$k) echo
"<td>$row[$k]</td>";
echo "</tr>";
}
echo "</table>";
?>
e) Create a web page using GUI components 4M
Ans. <!DOCTYPE html>
<html> Correct syntax
of any four
<head> GUI
<title>Registration form</title> components
<link rel="stylesheet" href="styel.css" type="text/css">
</head> 1M for each
component
Page 15 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619
<body>
<div class="main">
<div class="register">
<h2>Register Here</h2>
<form id="register" action="registrationform.php" method="post">
<label>First name:</label>
<br>
<input type="text" id="fname" name="fname" placeholder="Enter your first
name">
<br>
<br>
<label>Last name:</label>
<br>
<input type="text" id="lname" name="lname" placeholder="Enter your last
name">
<br>
<br>
<label>Date of Birth:</label>
<br>
<input type="date" id="dob" name="dob" placeholder="Enter your
Birthday">
<br>
<br>
<label>Gender:</label>
<br>
<input type="radio" id="male" name="gender"
value="male">
Page 16 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619
<span id="male">Male</span>
<input type="radio" id="female" name="gender"
value="female">
<span id="female">Female</span>
<br>
<br>
<br>
<label>Select Usertype</label>
<br>
<select name="usertype" id="usertype">
<option value="Student">Student</option>
<option value="Staff">Staff</option>
<option value="Alumni">Alumni</option>
</select>
<br>
<br>
<label>Password:</label>
<br>
<input type="password" id="pwd" name="password" placeholder="Enter
your password" pattern ="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}" title="Must
contain at least one number and one uppercase and lowercase letter, and at
least 8 or more characters" required>
<br>
<br>
</form>
</div><!-----end of register--->
Page 17 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619
</div><!-----end of main---->
</body>
</html>
5. Attempt any TWO of the following 12M
a) Implement any three data types used in PHP with illustration 6M
Ans. Data Types :
PHP provides eight types of values, or data types: Implementation
Four are scalar (single-value) types: integers, floating-point numbers, strings, / example of
and Booleans. any three data
Two are compound (collection) types: arrays and objects. types -2Meach
Two are special types: resource andNULL.
Integers: Integers are whole numbers, such as 1, 12, and 256. Integer literals
can be written in decimal, octal, or hexadecimal.
Example :
Decimal1998 ,−641 , +33
Octal0755 // decimal 493 , 010 // decimal 8
Hexadecimal0xFF // decimal 255 ,0x10 // decimal 16 , -0xDAD1 // decimal
−56017
Binary numbers begin with 0b, followed by a sequence of digits (0 and 1).
Like other values, you can include a sign in binary numbers: 0b01100000 //
decimal 1 ,0b00000010 // decimal 2
Page 18 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619
Arrays :An array holds a group of values, which you can identify by position
(a number, with zero being the first position) or some identifying name (a
string), called an associative index.
Example: The array() construct creates an array.
$person = array("Edison", "Wankel", "Crapper");
$creator = array('Light bulb' =>"Edison", 'Rotary Engine' =>"Wankel",
'Toilet' =>"Crapper");
Resource :Many modules provide several functions for dealing with the
outside world. For example, every database extension has at least a function
to connect to the database, a function to send a query to the database, and a
function to close the connection to the database. Example :$res =
database_connect();
database_query($res);
Page 19 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619
OR
Solution2:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$conn = mysqli_connect($servername, $username, $password);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>
OR
Solution 3:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
try {
$conn = new PDO("mysql:host=$servername;dbname=myDB", $username,
$password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
?>
Page 20 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 21 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619
Example :
<?php
class student
{
var $name;
function __construct($name)
{
$this->name=$name;
}
function __destruct()
{
echo "Destructor is executing " .$this->name;
}
}
$s1=new student("xyz");
?>
6. Attempt any TWO of the following 12M
a) Describe form controls – text box, text area, radio button, check box, list 6M
& buttons
Ans. Form Controls : Description of
each control
1. Textbox : A text box is used to enter data. It is a single line input on a web 1M
page.
Tag :<input type=“text”> : It is used to display a text box on a web page.
Attributes of <input> tag used with text box:
name=“ text” : Specify name of text box for unique identification.
maxlength=number : Specify maximum number of characters that can be
accepted in a textbox.
size=number : Specify the width of text box in number of characters.
value=“text” : Specify default text value that appears in the text box when
loaded on a web page.
Example:<input type=“text” name=“n1” maxlength=20 size=15
value=“Enter your name” >
Page 22 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Attributes:
name=“ text” : Specify name of the element for unique identification.
cols=number : Specify width of the text area.
rows=number : Specify height of the text area.
readonly : Specify a text area as read only element.
Example:<textarea name=“t1” cols=10 rows=10>Enter your
suggestions</textarea>
3. Radio / option button : Radio buttons are used to display multiple options
from which user can select only one option. When a radio button is selected
by user, a dot symbol appears inside button. Multiple option buttons are
group together to allow user to select only one option from the group. A
group can be created by giving same name to all option buttons in that group.
Tag :<input type=“radio”> : It is used to display a radio button on a web
page.
Attributes of <input> tag used with radio button:
name=“ text” : Specify name of radio button for unique identification.
value=“text” : Specify value to be returned to the destination if that radio
button is selected.
checked: Specify default selection
Example:<input type=“radio” name=“r1” value=“male”>male
<input type=“radio” name=“r1” value=“female” checked>female
Page 23 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619
iii) Reset button : Reset button is used to clear all elements with their
original state after user clicks on it.
Page 24 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619
__call() :In PHP, for function overloading , __call() method is used. This
function is triggered while invoking overloaded methods in the object
context.The $name argument is the name of the method being called.
The $arguments argument is an enumerated array containing the parameters
passed to the $named method.
Example :
<?php
class Shape1 {
const PI1 = 3.142 ;
function __call($name1,$arg1){
if($name1 == 'area1')
switch(count($arg1)){
Page 25 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619
case 0 : return 0 ;
case 1 : return self::PI1 * $arg1[0] ;
case 2 : return $arg1[0] * $arg1[1];
}
}
}
$circle1 = new Shape1();
echo "Area of Circle= ".$circle1->area1(3);
echo "<br><br>";
$rect1 = new Shape1();
echo "Area of Rectangle= ".$rect1->area1(8,6);
?>
ii) Mysqli_connect()
Mysqli_connect() function opens a new connection to the MySQL server.
Syntax :
mysqli_connect(host, username, password, dbname)
Example :
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$conn = mysqli_connect($servername, $username, $password);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>
Page 26 / 26