Web Technologies
Comprehensive exam revision notes for BCA-303N Unit 2 (XML Technologies & Server-Side PHP Programming). Includes Section A (2M), Section B (5M), and Section C (15M) questions, answers, and diagrams.
Web Technologies
XML Technologies & Server-Side PHP Programming
Core Definitions & Key Concepts
What does XML stand for and what is its primary purpose
XML (eXtensible Markup Language) is a W3C-standard, platform-independent text format designed to store, transport, and structure data, separating content from display formatting.
What is the difference between a 'Well-Formed' and a 'Valid' XML document
- Well-Formed: Follows XML basic syntax rules (single root element, matching closing tags, case-sensitive tags, properly nested elements, quoted attribute values).
- Valid: A well-formed XML document that additionally conforms to a declared schema (DTD or XML Schema / XSD).
Compare DTD (Document Type Definition) and XML Schema (XSD)
| Feature | DTD | XML Schema (XSD) |
|---|---|---|
| Syntax | Unique non-XML syntax | Standard XML syntax (<xs:schema>) |
| Data Types | Minimal (Strings only - PCDATA, CDATA) | Rich built-in types (integer, date, boolean, decimal) |
| Namespaces | Does not support XML Namespaces | Full native support for Namespaces |
| Extensibility | Fixed, non-extensible | Extensible with custom user types |
What is XSLT and what is its primary function
XSLT (Extensible Stylesheet Language Transformations) transforms XML source documents into other formats such as HTML, XHTML, plain text, or alternative XML structures using transformation rule templates.
The difference between SAX and DOM XML parsers
- DOM (Document Object Model): Tree-based; loads the entire XML file into memory as an interactive node graph (high memory, enables random access).
- SAX (Simple API for XML): Event-driven; streams through XML linearly firing events (
startElement,endElement) without loading everything in memory (low memory footprint).
What does PHP stand for and how are PHP code blocks delimited
PHP stands for Hypertext Preprocessor (recursive acronym). PHP code blocks are delimited by <?php and ?> tags and execute on the server.
Name four core PHP Superglobal arrays
$_GET: URL query parameters.$_POST: Form payload submitted via POST.$_SESSION: Session variables stored on server.$_COOKIE: HTTP cookie values sent by browser.
What is the purpose of session_start() in PHP
session_start() initializes a new session or resumes an existing session based on a session identifier passed via a GET/POST request or via cookie (PHPSESSID). It must be called before sending any HTML output.
include and require in PHP
include: If the specified file is missing, it emits a warning (`E_WARNING`) and script execution continues.require: If missing, it raises a fatal error (`E_COMPILE_ERROR`) and halts script execution immediately.
How do you prevent SQL Injection in PHP
By using Prepared Statements with parameterized queries via PDO (PHP Data Objects) or MySQLi, which separates SQL query structure from untrusted user inputs.
Conceptual & Architectural Analysis
The Structure of an XML Schema (XSD) with a Comprehensive Example
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- Root Element Declaration -->
<xs:element name="university">
<xs:complexType>
<xs:sequence>
<xs:element name="student" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="rollNumber" type="xs:positiveInteger"/>
<xs:element name="fullName" type="xs:string"/>
<xs:element name="course" type="xs:string"/>
<xs:element name="marks" type="xs:decimal"/>
</xs:sequence>
<xs:attribute name="category" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>- Features: Strongly typed tags, cardinality rules (
maxOccurs), and attribute constraints (use="required").
The Complete PHP Session Lifecycle and State Management
PHP Session Architecture
[ CLIENT (Browser) ] [ SERVER (Apache / PHP) ]
| |
| ----- 1. Initial Request (No Cookie) --------> |
| | -> session_start()
| | -> Generates unique 32-char ID
| | e.g. "a8f9c1..."
| | -> Creates /tmp/sess_a8f9c1...
| <-- 2. Response + Set-Cookie: PHPSESSID=... -- |
| |
| ----- 3. Subsequent Request with Cookie -----> |
| Cookie: PHPSESSID=a8f9c1... | -> session_start()
| | -> Loads $_SESSION from file- Destruction:
session_unset()clears variables in memory;session_destroy()deletes the session data from the server's filesystem storage.
File Upload Handling in PHP with $_FILES
When uploading files via <form method="POST" enctype="multipart/form-data">:
- The superglobal
$_FILES['uploaded_file']provides:
name: Original client filename.type: MIME type (e.g.,image/png).size: File size in bytes.tmp_name: Temporary location on server.error: Error code (UPLOAD_ERR_OK = 0).
- Function
move_uploaded_file(tmp_name, destination)securely moves the validated file to the permanent upload folder.
XML Namespaces and Why They Prevent Naming Collisions
When combining XML documents from different sources, tag name collisions occur (e.g., <table for furniture vs <table> for HTML data).
- Solution: XML Namespaces assign unique URIs via
xmlns:prefix="URI":
1<root xmlns:f="https://furnitures.org/specs" xmlns:h="http://www.w3.org/1999/xhtml">2 <f:table><f:name>Oak Coffee Table</f:name></f:table>3 <h:table><h:tr><h:td>Student Name</h:td></h:tr></h:table>4</root>Compare PHP GET vs POST Security and Processing
Superglobal Input Handling
$_GET: Data appears in query string; easily manipulated via address bar; vulnerable to URL logging in proxy servers. Never use for passwords, payment data, or state mutations.$_POST: Data sent in HTTP body; not visible in browser address bar; suitable for large files and passwords.- Sanitization: Always apply
htmlspecialchars()andfilter_var()before displaying or processing input to prevent Cross-Site Scripting (XSS).
In-Depth Analysis & Implementation
Build a Complete Secure PHP Student Management CRUD Application with Database Connectivity, Session Authentication, and Prepared Statements
<?php
// session_auth.php: Complete Authentication and CRUD Module
session_start();
// 1. Database Connection via PDO
$dsn = "mysql:host=localhost;dbname=mjpru_exam;charset=utf8mb4";
$db_user = "root";
$db_pass = "secret";
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false, // Ensures native server-side prepared statements
];
try {
$pdo = new PDO($dsn, $db_user, $db_pass, $options);
} catch (PDOException $e) {
die("Database connection failed: " . htmlspecialchars($e->getMessage()));
}
// 2. Authentication Check
if (!isset($_SESSION['user_id'])) {
// Handle Login
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['login'])) {
$email = trim($_POST['email']);
$password = $_POST['password'];
$stmt = $pdo->prepare("SELECT id, username, password_hash FROM users WHERE email = :email");
$stmt->execute(['email' => $email]);
$user = $stmt->fetch();
if ($user && password_verify($password, $user['password_hash'])) {
session_regenerate_id(true); // Protect against Session Fixation
$_SESSION['user_id'] = $user['id'];
$_SESSION['username'] = $user['username'];
header("Location: student_portal.php");
exit();
} else {
$error = "Invalid credentials!";
}
}
}
// 3. Secure Student Record Insertion (POST)
if (isset($_SESSION['user_id']) && $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_student'])) {
$roll_no = filter_input(INPUT_POST, 'roll_no', FILTER_VALIDATE_INT);
$student_name = trim(htmlspecialchars($_POST['student_name']));
$course = trim(htmlspecialchars($_POST['course']));
$marks = filter_input(INPUT_POST, 'marks', FILTER_VALIDATE_FLOAT);
if ($roll_no && !empty($student_name) && $marks !== false) {
// Parameterized Query eliminates SQL Injection
$insertStmt = $pdo->prepare("INSERT INTO students (roll_no, student_name, course, marks) VALUES (:roll, :name, :course, :marks)");
$insertStmt->execute([
'roll' => $roll_no,
'name' => $student_name,
'course' => $course,
'marks' => $marks
]);
$msg = "Student successfully enrolled!";
} else {
$error = "Validation failed. Please verify input formats.";
}
}
// 4. Retrieve Student Records
$students = [];
if (isset($_SESSION['user_id'])) {
$query = $pdo->query("SELECT * FROM students ORDER BY roll_no ASC");
$students = $query->fetchAll();
}
?>
<!DOCTYPE html>
<html>
<head><title>MJPRU BCA PHP Portal</title></head>
<body>
<h1>Welcome, <?php echo htmlspecialchars($_SESSION['username'] ?? 'Guest'); ?></h1>
<?php if (isset($error)) echo "<p style='color:red;'>$error</p>"; ?>
<?php if (isset($msg)) echo "<p style='color:green;'>$msg</p>"; ?>
<table border="1" cellpadding="8">
<tr><th>Roll No</th><th>Name</th><th>Course</th><th>Marks</th></tr>
<?php foreach ($students as $s): ?>
<tr>
<td><?= htmlspecialchars($s['roll_no']) ?></td>
<td><?= htmlspecialchars($s['student_name']) ?></td>
<td><?= htmlspecialchars($s['course']) ?></td>
<td><?= htmlspecialchars($s['marks']) ?></td>
</tr>
<?php endforeach; ?>
</table>
</body>
</html>XSLT Transformation with a Complete XML Source Document, XSL Stylesheet, and Transformed Output
End-to-End XSLT Transformation
1. Input Source XML (students.xml):
1<?xml version="1.0" encoding="UTF-8"?>2<?xml-stylesheet type="text/xsl" href="transform.xsl"?>3<class>4 <student roll="101">5 <name>Amit Kumar</name>6 <subject>Web Technologies</subject>7 <score>88</score>8 </student>9 <student roll="102">10 <name>Priya Sharma</name>11 <subject>Artificial Intelligence</subject>12 <score>94</score>13 </student>14</class>2. XSL Transformation Stylesheet (transform.xsl):
1<?xml version="1.0" encoding="UTF-8"?>2<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">3 <xsl:template match="/">4 <html>5 <body>6 <h2>MJPRU BCA Student Performance Report</h2>7 <table border="1">8 <tr bgcolor="#9acd32">9 <th>Roll</th><th>Student Name</th><th>Subject</th><th>Score</th>10 </tr>11 <xsl:for-each select="class/student">12 <xsl:sort select="score" order="descending"/>13 <tr>14 <td><xsl:value-of select="@roll"/></td>15 <td><xsl:value-of select="name"/></td>16 <td><xsl:value-of select="subject"/></td>17 <td><xsl:value-of select="score"/></td>18 </tr>19 </xsl:for-each>20 </table>21 </body>22 </html>23 </xsl:template>24</xsl:stylesheet>3. Execution Mechanics:
- The browser or an XSLT processor (e.g.,
XSLTProcessorin JS orxsltprocin PHP) matches the root/template. <xsl:for-each>iterates over<student>nodes, sorts by<score>, and transforms hierarchical XML tags into an HTML table structure.
DTD Element and Attribute Declarations with Symbols (?, *, +, |, ,)
Complete DTD Syntax and Cardinality Operators
Syntax Rules:
- `?` (Zero or One): Element is optional but cannot appear more than once.
- *`` (Zero or More):** Element can appear any number of times.
- `+` (One or More): Element must appear at least once.
- `,` (Sequence): Elements must appear in strict specified order.
- `|` (Alternative): Either element may appear (choice).
<!DOCTYPE university [
<!ELEMENT university (department+)>
<!ELEMENT department (dept_name, faculty*, course+)>
<!ELEMENT dept_name (#PCDATA)>
<!ELEMENT faculty (faculty_name, designation?, phone*)>
<!ELEMENT faculty_name (#PCDATA)>
<!ELEMENT designation (#PCDATA)>
<!ELEMENT phone (#PCDATA)>
<!ELEMENT course (course_code, title, credits)>
<!ELEMENT course_code (#PCDATA)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT credits (#PCDATA)>
<!-- Attribute Declarations -->
<!ATTLIST department
id ID #REQUIRED
code CDATA #IMPLIED
status (active | archived) "active"
>
]>Important Exam Points & Quick Revision
Examiner high-yield focus: DTD vs XSD differences, PHP Session handling code, and XSLT transformation rules.
100% left on this page — finishing it closes the gap for XML Technologies & Server-Side PHP Programming.
XML Technologies & Server-Side PHP Programming still counts as a weak topic until you finish this note and answer its questions.
Practise this unitTest Your Understanding
Now that you've read through these notes, practice unit MCQs to identify weak points and solidify your learning before exams.