Blog
Web System & Technology Past Paper 2014 – BS IT 4th Term UOS (IT-372)
University of Sargodha BS IT 4th term Web System & Technology (IT-372) paper, 2014 exam, session 2012-16 (80 marks, 2:30 hours). The paper is retyped below without the handwritten number, followed by solved answers for all 16 short questions (CSS, HTML5, error correction and PHP output) and complete code for all subjective questions: an XHTML form with age validation, PHP insert/display, JavaScript shapes, PHP sessions and CSS menus.
Solved answers
Q1 – Short answers (16 × 2)
a. CSS for Times New Roman, 14pt, bold. p { font-family: "Times New Roman", serif; font-size: 14pt; font-weight: bold; }
b. Inline CSS. Style written directly in an element’s style attribute, applying only to that element: <p style="color:red;">Hi</p>.
c. Purpose of CSS. To separate presentation (colours, fonts, layout, spacing) from HTML content, giving consistent design across pages, easier maintenance, smaller pages and responsive layouts.
d. HTML5. The fifth version of HTML: new semantic elements (header, nav, article, section, footer), native audio/video, canvas and SVG, new form input types (date, email), local storage and offline support.
e. Web browser. Software that requests web pages from servers using HTTP and displays HTML/CSS/JavaScript to the user. Examples: Google Chrome, Mozilla Firefox, Microsoft Edge, Safari, Opera.
f. GET vs POST. GET sends form data in the URL query string (visible, limited length, can be bookmarked, for retrieving data). POST sends data in the request body (not visible in URL, no size limit, used for sensitive data and changes such as login or insert).
g. Role of JavaScript. Client-side scripting that makes pages interactive: form validation, reacting to events, changing content and styles dynamically (DOM), animations, and loading data without reloading (AJAX).
h. Why external CSS is better. One .css file styles the whole site, so changes are made in one place; HTML stays clean; the file is cached by the browser, so pages load faster.
i. HTTP response header. Name–value lines the server sends before the body, describing the response: status line (HTTP/1.1 200 OK), Content-Type, Content-Length, Set-Cookie, Cache-Control, Server, Date.
j. body{background-image: url(logo.gif); background-position: bottom right;} This rule is already valid CSS. A safer version quotes the URL and stops tiling: body { background-image: url("logo.gif"); background-repeat: no-repeat; background-position: bottom right; }
k. document.writeln(<h1>… The string is not quoted and the bracket is not closed: document.writeln("<h1>Welcome to JavaScript</h1>");
l. <?php echo “<p>Hello World</p>”?> A semicolon should end the statement (it is optional just before ?>, but required by good style): <?php echo "<p>Hello World</p>"; ?>
m. XHTML: <br> Empty elements must be closed: <h3>I need a break.<br /></h3>
n. XHTML: <SUB> Tags must be lower-case: <sub>x</sub><sup>2</sup>
o. strcmp output. strcmp returns 0 when the strings are equal, so the output is 0 (tested in PHP 8).
p. count($lang) output. The array has 3 elements, so the output is 3 (tested).
Q2 – XHTML form with age validation
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Registration Form</title>
<script type="text/javascript">
//<![CDATA[
function validateAge() {
var dob = new Date(document.getElementById("dob").value);
if (isNaN(dob.getTime())) { alert("Please enter date of birth"); return false; }
var today = new Date();
var age = today.getFullYear() - dob.getFullYear();
var m = today.getMonth() - dob.getMonth();
if (m < 0 || (m === 0 && today.getDate() < dob.getDate())) age--;
if (age < 18) { alert("Age must be at least 18 years"); return false; }
return true;
}
//]]>
</script>
</head>
<body>
<form action="mydb.php" method="post" onsubmit="return validateAge();">
<p>First Name: <input type="text" name="fname" /></p>
<p>Last Name: <input type="text" name="lname" /></p>
<p>Gender:
<input type="radio" name="gender" value="Male" /> Male
<input type="radio" name="gender" value="Female" /> Female</p>
<p>Date of Birth: <input type="date" name="dob" id="dob" /></p>
<p>User Name: <input type="text" name="uname" /></p>
<p>Password: <input type="password" name="pass" /></p>
<p>Address: <textarea name="address" rows="3" cols="30"></textarea></p>
<p><input type="submit" value="Submit" /></p>
</form>
</body>
</html>The form posts to mydb.php; validateAge() computes the age from the date of birth and cancels submission if it is under 18. (The file was checked as well-formed XML.)
Q3 – Insert into LoginDb and display
<?php
// Table: CREATE TABLE users (id INT AUTO_INCREMENT PRIMARY KEY, fname VARCHAR(50),
// lname VARCHAR(50), gender VARCHAR(10), dob DATE, uname VARCHAR(50),
// pass VARCHAR(255), address VARCHAR(200));
$conn = new mysqli("localhost", "root", "", "LoginDb");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$hash = password_hash($_POST["pass"], PASSWORD_DEFAULT); // never store plain passwords
$stmt = $conn->prepare("INSERT INTO users (fname, lname, gender, dob, uname, pass, address)
VALUES (?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("sssssss", $_POST["fname"], $_POST["lname"], $_POST["gender"],
$_POST["dob"], $_POST["uname"], $hash, $_POST["address"]);
if ($stmt->execute()) echo "<p>Record inserted successfully.</p>";
$stmt->close();
}
// display all records
$result = $conn->query("SELECT fname, lname, gender, dob, uname, address FROM users");
echo "<table border='1'><tr><th>First</th><th>Last</th><th>Gender</th><th>DOB</th><th>User</th><th>Address</th></tr>";
while ($row = $result->fetch_assoc()) {
echo "<tr>";
foreach ($row as $v) echo "<td>" . htmlspecialchars($v) . "</td>";
echo "</tr>";
}
echo "</table>";
$conn->close();
?>The script uses a prepared statement (safe from SQL injection), stores the password as a hash, inserts the posted values into the users table of LoginDb and then shows all records in an HTML table. (Checked with php -l: no syntax errors.)
Q4 – Shapes with JavaScript
<!DOCTYPE html>
<html>
<head><title>Shapes with JavaScript</title></head>
<body>
<canvas id="c" width="460" height="160" style="border:1px solid #000"></canvas>
<script>
var ctx = document.getElementById("c").getContext("2d");
// rectangle
ctx.fillStyle = "steelblue";
ctx.fillRect(20, 30, 100, 80);
// circle
ctx.beginPath();
ctx.arc(200, 70, 45, 0, 2 * Math.PI);
ctx.fillStyle = "orange";
ctx.fill();
// triangle
ctx.beginPath();
ctx.moveTo(280, 120); ctx.lineTo(340, 20); ctx.lineTo(400, 120);
ctx.closePath();
ctx.fillStyle = "seagreen";
ctx.fill();
// line
ctx.beginPath();
ctx.moveTo(20, 145); ctx.lineTo(440, 145);
ctx.stroke();
</script>
</body>
</html>The canvas API draws a filled rectangle, circle and triangle and a line.
Q5 – Advantages and disadvantages of web-based applications
| Advantages | Disadvantages |
|---|---|
| Accessible anywhere through a browser, on any OS/device | Need a reliable internet connection |
| No installation; updates are made once on the server | Usually slower than desktop apps; depends on server performance |
| Cheaper deployment and maintenance; central data | Security risks (hacking, data breaches); data held by provider |
| Easy to scale and share among many users | Browser compatibility issues; limited access to device hardware |
Q6 – Session in PHP
A session stores user data on the server across multiple pages. PHP gives each visitor a session ID (kept in a cookie, PHPSESSID); session_start() must be called at the top of each page, and values are kept in the $_SESSION array until the session is destroyed or expires.
webpage1.php
<?php
session_start(); // start or resume the session
$_SESSION["username"] = "Ali"; // store data in session variables
$_SESSION["course"] = "Web Systems";
header("Location: webpage2.php"); // redirect to the second page
exit;
?>webpage2.php
<?php
session_start(); // must be called on every page that uses the session
if (isset($_SESSION["username"])) {
echo "Welcome " . $_SESSION["username"] . "<br />";
echo "Course: " . $_SESSION["course"];
} else {
echo "No session data found.";
}
?>Opening webpage1.php redirects to webpage2.php, which shows “Welcome Ali” and “Course: Web Systems”. (Both files checked with php -l.)
Q7 – Horizontal and vertical menus with an unordered list
<!DOCTYPE html>
<html>
<head>
<title>Menus</title>
<style>
ul { list-style-type: none; margin: 0; padding: 0; }
/* horizontal menu */
ul.hmenu { overflow: hidden; background: #333; }
ul.hmenu li { float: left; }
ul.hmenu li a { display: block; color: #fff; padding: 12px 16px; text-decoration: none; }
ul.hmenu li a:hover { background: #555; }
/* vertical menu */
ul.vmenu { width: 180px; background: #eee; margin-top: 20px; }
ul.vmenu li a { display: block; color: #000; padding: 8px 12px; text-decoration: none; }
ul.vmenu li a:hover { background: #ccc; }
</style>
</head>
<body>
<ul class="hmenu">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>
<ul class="vmenu">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>
</body>
</html>
