Skip to main content

Chapter 3

Web Technology II

TU BIM past exam questions

Past questions and answers

22 questions set from this chapter. Most repeated first.

  • 2024 AD Model · 1 mark

What is server-side script?

Answer

A server-side script is a program that runs on the web server (not in the browser) when a request is received. It processes the request, may access databases and files, and sends the generated output, usually HTML, back to the client. PHP, ASP.NET, JSP and Node.js are examples.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 AD Model · 1 mark

What is PHP superglobal?

Answer

Superglobals are built-in PHP variables that are always available in every scope (function, class or file) without using the global keyword. Examples are $_GET, $_POST, $_REQUEST, $_SESSION, $_COOKIE, $_SERVER, $_FILES, $_ENV and $GLOBALS.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 AD Model · 1 mark

Define associative array.

Answer

An associative array is a PHP array in which each value is accessed by a named (string) key instead of a numeric index, for example $age = ["Ram" => 20, "Sita" => 22]; and echo $age["Ram"];.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 AD Model · 1 mark

What is static method?

Answer

A static method is a class method declared with the static keyword. It belongs to the class itself, so it can be called without creating an object, using ClassName::method(). It cannot use $this.

class Math { public static function square($n) { return $n * $n; } }
echo Math::square(4); // 16

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 AD Model · 1 mark

Why do we need file handling?

Answer

File handling is needed to create, read, write, update, delete and upload files on the server, so that data can be stored permanently (for example logs, configuration, text data, uploaded images and documents) and survive after the script ends.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 AD Model · 1 mark

List some benefits of storing website data in databases.

Answer

  • Data is organised and can be searched, sorted and filtered quickly using SQL.
  • Large amounts of data can be handled efficiently and shared by many users at the same time.
  • It gives security (user permissions, backups) and data integrity (constraints, transactions).
  • It reduces redundancy and makes content dynamic and easy to update.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 AD Model · 1 mark

What are the uses of session?

Answer

A session stores user information on the server across multiple pages, identified by a session ID. It is used for:

  • keeping users logged in and authentication;
  • shopping carts;
  • storing user preferences and temporary data (such as form data in multi-step forms);
  • tracking user activity securely, since data is not kept in the browser.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 AD Model · 1 mark

What is server-side framework?

Answer

A server-side framework is a collection of ready-made libraries, tools and a structure (often MVC) that helps developers build web applications faster and in an organised way. It provides routing, database access, templates, security and authentication. Examples are Laravel and CodeIgniter (PHP), Django (Python), Express (Node.js) and Spring (Java).

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 AD Model · 1 mark

What is dynamic website?

Answer

A dynamic website is a website whose content is generated at the time of the request by server-side scripts, usually using data from a database. The content can change according to the user, time or input (for example, a login page, e-commerce site or news portal), unlike a static site, which shows fixed HTML pages.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 AD Model · 3 marks

Compare GETwith_GET with _POST.

Answer

$_GET and $_POST are superglobals which collect form data.

Basis$_GET$_POST
Data locationSent in the URL as a query string (page.php?id=5&name=Ram)Sent in the body of the HTTP request
VisibilityVisible in the address bar, history and logsNot visible in the URL
SecurityLess secure; unsuitable for passwords and sensitive dataMore secure than GET
Data sizeLimited (URL length, about 2000 characters)No practical limit
BookmarkingPage can be bookmarked and sharedCannot be bookmarked
UseSearching, filtering, retrieving dataForms for login, registration, file upload, inserting data
Data typeOnly text (ASCII)Text and binary data

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 AD Model · 3 marks

Explain regular expression with example.

Answer

A regular expression (regex) is a pattern made of special characters used to search, match, validate or replace text in a string. In PHP, the PCRE functions preg_match(), preg_match_all(), preg_replace() and preg_split() are used. The pattern is written between delimiters such as / /.

Common symbols: ^ start, $ end, . any character, * zero or more, + one or more, ? optional, [a-z] character range, \d digit, {n} exactly n times.

<?php
$email = "ram@example.com";
if (preg_match("/^[\w.]+@[a-z]+\.[a-z]{2,}$/i", $email)) {
    echo "Valid email";
} else {
    echo "Invalid email";
}

$phone = "9841234567";
echo preg_match("/^9\d{9}$/", $phone); // 1 (matches a 10-digit number starting with 9)
?>

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 AD Model · 3 marks

How do you set and get cookies in PHP?

Answer

Setting a cookie: use setcookie(name, value, expire, path, domain, secure, httponly). It must be called before any HTML output.

<?php
setcookie("username", "Ram", time() + 86400, "/"); // valid for 1 day
?>

Getting a cookie: read it from the $_COOKIE superglobal. A cookie becomes available on the next request after it has been set.

<?php
if (isset($_COOKIE["username"])) {
    echo "Welcome " . $_COOKIE["username"];
} else {
    echo "Cookie not set";
}
?>

Deleting a cookie: set its expiry time in the past, setcookie("username", "", time() - 3600, "/");.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 AD Model · 3 marks

How do you access to user credentials from PHP?

Answer

User credentials (such as username and password) are accessed in PHP from the submitted login form using the $_POST superglobal (or $_GET), and are then checked against the database.

<form method="post" action="login.php">
  <input type="text" name="username">
  <input type="password" name="password">
  <input type="submit" value="Login">
</form>
<?php
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $username = $_POST["username"];
    $password = $_POST["password"];
    // compare with the stored hashed password from the database
    // if (password_verify($password, $hash)) { $_SESSION["user"] = $username; }
}
?>

Passwords should be stored as hashes (password_hash()), verified with password_verify(), and queries should use prepared statements. After login, the user's identity is kept in $_SESSION. For HTTP authentication, $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW'] can be used.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 AD Model · 3 marks

Discuss some benefits of server-side frameworks.

Answer

  • Faster development: Ready-made components for routing, forms, authentication and database access reduce the code to be written.
  • Better structure and maintainability: They follow patterns such as MVC and coding conventions, so the code is organised and easy to maintain in teams.
  • Security: Built-in protection against SQL injection, XSS and CSRF, along with password hashing and session handling.
  • Reusability and scalability: Reusable libraries and modules, caching and ORM support help to scale applications.
  • Community support: Documentation, plugins and active communities, and easy testing and deployment.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 AD Model · 3 marks

How do you define a class in PHP? Explain with suitable example.

Answer

A class is defined in PHP using the class keyword followed by the class name and a body in curly braces containing properties (variables) and methods (functions). Objects are created with new, and members are accessed with ->. The constructor is __construct(), and $this refers to the current object.

<?php
class Student {
    public $name;
    private $roll;

    public function __construct($name, $roll) {
        $this->name = $name;
        $this->roll = $roll;
    }

    public function display() {
        echo "Name: $this->name, Roll: $this->roll";
    }
}

$s1 = new Student("Sita", 5);
$s1->display();   // Name: Sita, Roll: 5
?>

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 AD Model · 5 marks

How do you create functions in PHP? Explain with example.

Answer

A function is a named block of reusable code defined with the function keyword, and executed only when it is called.

Syntax

function functionName($param1, $param2 = default) {
    // code
    return $value;   // optional
}

Example 1: simple function with parameters and return value

<?php
function add($a, $b) {
    return $a + $b;
}
echo add(5, 3);   // 8
?>

Example 2: default argument

<?php
function greet($name = "Guest") {
    echo "Hello $name";
}
greet("Ram");  // Hello Ram
greet();       // Hello Guest
?>

Example 3: pass by reference

<?php
function addOne(&$n) { $n++; }
$x = 10;
addOne($x);
echo $x;  // 11
?>

Points to remember:

  • Function names are not case sensitive and must begin with a letter or underscore.
  • Variables inside a function are local unless declared global or static.
  • Arguments can be passed by value (default) or by reference (&).
  • Type declarations can be used: function add(int $a, int $b): int.
  • A function can be called before its definition if it is defined at the top level of the file.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 1 MCQ

Loading…

  • 2024 AD Model · 5 marks

How do you handle exceptions in PHP?

Answer

An exception is an error condition that interrupts the normal flow of a program. PHP handles exceptions with try, catch, finally and throw.

  • try: contains the code which may cause an exception.
  • throw: raises (throws) an exception object.
  • catch: catches the exception and handles it. Several catch blocks may be used for different exception types.
  • finally: code which always runs, whether or not an exception occurred.
<?php
function divide($a, $b) {
    if ($b == 0) {
        throw new Exception("Division by zero is not allowed");
    }
    return $a / $b;
}

try {
    echo divide(10, 0);
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
} finally {
    echo "<br>Execution finished";
}
?>

Output:

Error: Division by zero is not allowed
Execution finished

Custom exceptions can be made by extending the Exception class, and set_exception_handler() can define a global handler for uncaught exceptions. Useful methods are getMessage(), getCode(), getLine() and getFile().

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 1 MCQ

Loading…

  • 2024 AD Model · 5 marks

Write a program in PHP that reads a file and displays vowels only.

Answer

<?php
$filename = "data.txt";

if (!file_exists($filename)) {
    die("File not found.");
}

$fp = fopen($filename, "r");
$vowels = "";

while (!feof($fp)) {
    $line = fgets($fp);
    // keep only vowels (both cases)
    $vowels .= preg_replace("/[^aeiouAEIOU]/", "", $line);
}
fclose($fp);

echo "Vowels in the file: " . $vowels . "<br>";
echo "Total vowels: " . strlen($vowels);
?>

The program opens the file for reading with fopen(), reads it line by line with fgets() until the end (feof()), removes all non-vowel characters using a regular expression, and displays the remaining vowels. A shorter alternative is preg_replace("/[^aeiou]/i", "", file_get_contents("data.txt")).

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 AD Model · 5 marks

Explain the process of connecting a PHP program with the database and inserting data into it.

Answer

PHP connects to a MySQL database using the MySQLi (or PDO) extension. The steps are:

  1. Create the database and table in MySQL, for example school and students(id, name, email).
  2. Connect to the server with mysqli_connect(host, username, password, database) and check for errors.
  3. Prepare the SQL INSERT statement with the values (taken from a form using $_POST).
  4. Execute the query with mysqli_query() or a prepared statement, and check the result.
  5. Close the connection with mysqli_close().
<?php
$conn = mysqli_connect("localhost", "root", "", "school");
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$name  = "Ram Sharma";
$email = "ram@example.com";

$stmt = mysqli_prepare($conn, "INSERT INTO students (name, email) VALUES (?, ?)");
mysqli_stmt_bind_param($stmt, "ss", $name, $email);

if (mysqli_stmt_execute($stmt)) {
    echo "Record inserted successfully";
} else {
    echo "Error: " . mysqli_error($conn);
}

mysqli_stmt_close($stmt);
mysqli_close($conn);
?>

A prepared statement is used to prevent SQL injection.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 AD Model · 10 marks

Write a server-side script in PHP to illustrate inserting and retrieving data to and from the database table. Create required connection using your own assumptions. Use HTML form to insert and display data.

Answer

Assumptions: MySQL server on localhost, user root with empty password, database school, and the table:

CREATE DATABASE school;
USE school;
CREATE TABLE students (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(50) NOT NULL,
    email VARCHAR(80) NOT NULL
);

students.php (the form, insertion and display are in a single file)

<?php
// Database connection
$conn = mysqli_connect("localhost", "root", "", "school");
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

// Insert data when the form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $name  = trim($_POST["name"]);
    $email = trim($_POST["email"]);

    if ($name != "" && $email != "") {
        $stmt = mysqli_prepare($conn, "INSERT INTO students (name, email) VALUES (?, ?)");
        mysqli_stmt_bind_param($stmt, "ss", $name, $email);
        if (mysqli_stmt_execute($stmt)) {
            $msg = "Record inserted successfully.";
        } else {
            $msg = "Error: " . mysqli_error($conn);
        }
        mysqli_stmt_close($stmt);
    } else {
        $msg = "All fields are required.";
    }
}
?>
<!DOCTYPE html>
<html>
<head><title>Student Records</title></head>
<body>
<h2>Add Student</h2>
<?php if (isset($msg)) echo "<p>$msg</p>"; ?>
<form method="post" action="">
    Name: <input type="text" name="name" required><br><br>
    Email: <input type="email" name="email" required><br><br>
    <input type="submit" value="Save">
</form>

<h2>Student List</h2>
<table border="1" cellpadding="5">
<tr><th>ID</th><th>Name</th><th>Email</th></tr>
<?php
// Retrieve and display data
$result = mysqli_query($conn, "SELECT * FROM students ORDER BY id");
if (mysqli_num_rows($result) > 0) {
    while ($row = mysqli_fetch_assoc($result)) {
        echo "<tr><td>" . $row["id"] . "</td><td>" .
             htmlspecialchars($row["name"]) . "</td><td>" .
             htmlspecialchars($row["email"]) . "</td></tr>";
    }
} else {
    echo "<tr><td colspan='3'>No records found</td></tr>";
}
mysqli_close($conn);
?>
</table>
</body>
</html>

Working: The HTML form sends the data with the POST method to the same page. The PHP code connects to the database, inserts the data using a prepared statement (safe against SQL injection), then runs a SELECT query and prints each row of the result in a table with mysqli_fetch_assoc(). htmlspecialchars() prevents XSS when the data is displayed.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 AD Model · 10 marks

What are the benefits of using arrays? Write a program to display sum and average of 10 numbers stored in a PHP array. Why do we need associative arrays?

Answer

Benefits of arrays

  • One variable can store many related values, so there is no need for many separate variables.
  • Elements are accessed easily by an index or a key, and loops can process them.
  • Sorting, searching, merging and other operations are easy using built-in functions (sort(), array_sum(), count(), in_array()).
  • They make the code short, organised and easy to maintain, and can represent lists, tables and records (multidimensional arrays).
  • PHP arrays are flexible: they can hold values of different types and grow dynamically.

Program: sum and average of 10 numbers

<?php
$numbers = [12, 7, 25, 8, 14, 30, 5, 18, 21, 10];

$sum = 0;
foreach ($numbers as $n) {
    $sum += $n;
}
$avg = $sum / count($numbers);

echo "Sum = " . $sum . "<br>";          // 150
echo "Average = " . $avg;               // 15
// Alternatively: array_sum($numbers) and array_sum($numbers)/count($numbers)
?>

Why we need associative arrays

An associative array uses meaningful named keys instead of numeric indexes, so data is easier to understand and access, for example $student = ["name" => "Sita", "age" => 20, "faculty" => "BIM"]; and echo $student["name"];. They are needed because:

  • they store data as key-value pairs, like a record or a database row (mysqli_fetch_assoc() returns one);
  • values can be found directly by key without remembering positions, and the order of elements does not matter;
  • they represent configuration data, form data ($_POST["email"]), JSON data and lookup tables clearly;
  • they make code more readable and less error prone than numeric indexes.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

Questions from TU BIM Fourth Semester ACC 202 Cost and Management Accounting Model Question 2024 (Faculty of Management model question 2024, BIM fourth semester (new course), via EducateNepal), TU BIM Fourth Semester ECO 206 Economics for Business Model Question 2024 (Faculty of Management model question 2024, BIM fourth semester (new course), via EducateNepal), TU BIM Fourth Semester IT 239 Web Technology II Model Question 2024 (Faculty of Management model question 2024, BIM fourth semester (new course), via EducateNepal), TU BIM Fourth Semester IT 240 Business Data Communication and Networking Model Question 2024 (Faculty of Management model question 2024, BIM fourth semester (new course), via EducateNepal), TU BIM Fourth Semester IT 220 Database Management System Model Question 2024 (Faculty of Management model question 2024, BIM fourth semester (new course), via EducateNepal), TU BIM Fourth Semester IT 241 Operating System Model Question 2024 (Faculty of Management model question 2024, BIM fourth semester (new course), via EducateNepal), TU BBA/BIM 4th Semester Cost and Management Accounting 2014 (model question) (Faculty of Management model question 2014 (old course), via EducateNepal), TU BIM Data Structure and Algorithm with Java (IT 218) 2015 AD (Board exam paper, 2015 AD), TU BIM Data Structure and Algorithm with Java (IT 218) 2016 AD (Board exam paper, 2016 AD), TU BIM Data Structure and Algorithm with Java (IT 218) 2017 AD (Board exam paper, 2017 AD), TU BIM Data Structure and Algorithm with Java (IT 218) 2018 AD (Board exam paper, 2018 AD), TU BIM Data Structure and Algorithm with Java (IT 218) 2019 AD (Board exam paper, 2019 AD), TU BIM Web Programming II (IT 219) 2015 AD (Board exam paper, 2015 AD), TU BIM Web Programming II (IT 219) 2016 AD (Board exam paper, 2016 AD), TU BIM Web Programming II (IT 219) 2017 AD (Board exam paper, 2017 AD), TU BIM Web Programming II (IT 219) 2018 AD (Board exam paper, 2018 AD), TU BIM Web Programming II (IT 219) 2019 AD (Board exam paper, 2019 AD), TU BIM Database Management System (ITC 218) 2007 AD (Board exam paper, 2007 AD), TU BIM Database Management System (ITC 218) 2008 AD (Board exam paper, 2008 AD), TU BIM Database Management System (ITC 218) 2009 AD (Board exam paper, 2009 AD), TU BIM Database Management System (ITC 218) 2010 AD (Board exam paper, 2010 AD), TU BIM Database Management System (ITC 218) 2011 AD (Board exam paper, 2011 AD), TU BIM Database Management System (ITC 218) 2012 AD (Board exam paper, 2012 AD), TU BIM Database Management System (ITC 218) 2013 AD (Board exam paper, 2013 AD), TU BIM Database Management System (ITC 218) 2014 AD (Board exam paper, 2014 AD), TU BIM Database Management System (ITC 218) 2015 AD (Board exam paper, 2015 AD), TU BIM Database Management System (ITC 218) 2016 AD (Board exam paper, 2016 AD), TU BIM Database Management System (ITC 218) 2017 AD (Board exam paper, 2017 AD), TU BIM Database Management System (ITC 218) 2018 AD (Board exam paper, 2018 AD), TU BIM Database Management System (ITC 218) 2019 AD (Board exam paper, 2019 AD), TU BIM Micro Economics (ECO 201) 2007 AD (Board exam paper, 2007 AD), TU BIM Micro Economics (ECO 201) 2008 AD (Board exam paper, 2008 AD), TU BIM Micro Economics (ECO 201) 2009 AD (Board exam paper, 2009 AD), TU BIM Micro Economics (ECO 201) 2010 AD (Board exam paper, 2010 AD), TU BIM Micro Economics (ECO 201) 2014 AD (Board exam paper, 2014 AD), TU BIM Micro Economics (ECO 201) 2015 AD (Board exam paper, 2015 AD), TU BIM Micro Economics (ECO 201) 2016 AD (Board exam paper, 2016 AD), TU BIM Micro Economics (ECO 201) 2017 AD (Board exam paper, 2017 AD), TU BIM Micro Economics (ECO 201) 2018 AD (Board exam paper, 2018 AD) and TU BIM Micro Economics (ECO 201) 2019 AD (Board exam paper, 2019 AD). Answers are written for this site; check them against your class notes.