Tribhuwan University

Institute of Science and Technology

2081

Bachelor Level / Third Year / Fifth Semester / Science

Bachelors in Information Technology (BIT301)

(Web Technology II)

Full Marks: 60

Pass Marks: 24

Time: 3 Hours

Candidates are required to give their answers in their own words as for as practicable.

The figures in the margin indicate full marks.

Section A

Long Answers Questions

Attempt any TWO questions.
[2*10=20]
1.
What is server side scripting? How can you define and declare variables in PHP? Write PHP programs to demonstrate concepts of while and do while loops.[10]

Server Side Scripting, PHP Variables, and Loops


Part A: Server Side Scripting

Server side scripting is a technique where scripts are executed on the web server, and the resulting output (usually HTML) is sent to the client's browser.

  • The user cannot see the source code; only the processed output is visible
  • The server processes the script, interacts with databases, performs logic, and generates dynamic web pages
  • Examples of server side scripting languages: PHP, Python, ASP.NET, Node.js, Java (JSP)

How it works:

  • Client sends a request to the server (e.g., requesting a .php page)
  • The web server identifies the script and passes it to the PHP interpreter
  • The interpreter executes the code and returns HTML output
  • The server sends this HTML response back to the client browser

Part B: Defining and Declaring Variables in PHP

In PHP, a variable is declared using the dollar sign ($) followed by the variable name. PHP is a loosely typed language, so no data type declaration is needed.

Rules for declaring variables:

  • A variable starts with $ followed by the name (e.g., $name)
  • Variable name must start with a letter or underscore (not a number)
  • Variable names are case-sensitive ($Age and $age are different)
  • No need to declare data type — PHP automatically assigns it

Example:

<?php
  $name = "John";        // String variable
  $age = 25;             // Integer variable
  $price = 99.5;         // Float variable
  $is_active = true;     // Boolean variable

  echo $name;
  echo $age;
?>

Variable Scopes in PHP:

  • Local – declared inside a function, accessible only within that function
  • Global – declared outside a function, accessible outside but not inside functions (unless using global keyword)
  • Static – retains its value even after the function execution ends

Part C: While Loop in PHP

The while loop executes a block of code as long as the specified condition is true. It is an entry-controlled loop (condition is checked before execution).

Syntax:

while (condition) {
    // code to execute
}

Program: Print numbers 1 to 5 using while loop

<?php
  $i = 1;
  while ($i <= 5) {
      echo "Number: " . $i . "<br>";
      $i++;
  }
?>

Output:

Number: 1
Number: 2
Number: 3
Number: 4
Number: 5

Part D: Do-While Loop in PHP

The do-while loop executes the block of code at least once, and then repeats as long as the condition is true. It is an exit-controlled loop (condition is checked after execution).

Syntax:

do {
    // code to execute
} while (condition);

Program: Print numbers 1 to 5 using do-while loop

<?php
  $i = 1;
  do {
      echo "Number: " . $i . "<br>";
      $i++;
  } while ($i <= 5);
?>

Output:

Number: 1
Number: 2
Number: 3
Number: 4
Number: 5

Key Difference: While vs Do-While

Feature While Loop Do-While Loop
Type Entry-controlled Exit-controlled
Minimum execution 0 times (if condition is false initially) At least 1 time
Condition check Before the loop body After the loop body

Conclusion: Server side scripting enables dynamic web content generation. PHP provides simple variable declaration using $ and supports both while (entry-controlled) and do-while (exit-controlled) loops for repetitive tasks.

2.
How can you define and declare functions? Differentiate global variable from static variable. Write a PHP program to demonstrate the use of global and static variables.[10]
3.
What is a PHP Data Object? How does MySQLi Object Interface work? Write a PHP program to read data elements from a database table and display in a page.[10]
Section B

Short Answers Questions

Attempt any Eight questions.
[8*5=40]
4.
How is class different from interface? Illustrate with an example. [5]
5.
What is a session? How can you handle sessions in PHP? [5]
6.
Define error handlers and error logs with examples. [5]
7.
Write a PHP program to read a file. [5]
8.
Describe the concepts of display_errors, variables_order and request_order in PHP.ini Settings. [5]
9.
Describe the date time functions with examples. [5]
10.
Write a PHP program to demonstrate use of constructor. [5]
11.
How conversion between arrays and variables is done using extract() and compact() functions? [5]
12.
What is exploding and imploding of strings? Illustrate with an example. [5]