UNIT 3: Web Technologies (Based on Past Exam Questions)
1. HTML and XHTML Fundamentals
Page Layout and Linking
-
Page Layout: Structuring a webpage using semantic elements (
<header>,<nav>,<main>,<section>,<article>,<footer>) and non-semantic containers (<div>,<span>). -
Linking:
-
Hyperlinks: Created using the
<a>(anchor) tag with thehrefattribute.<a href="https://www.example.com" target="_blank">Visit Example</a> -
Anchors (Bookmarks): Link to a specific section within the same page using
idandhrefwith#.<h2 id="section1">Section 1</h2> <a href="#section1">Jump to Section 1</a>
-
Types of Lists
| List Type | Tag | Purpose | Example |
|---|---|---|---|
| Ordered List | <ol> |
Sequential items (numbered). | <ol><li>First</li><li>Second</li></ol> |
| Unordered List | <ul> |
Non-sequential items (bulleted). | <ul><li>Item A</li><li>Item B</li></ul> |
| Definition List | <dl> |
Terms and their definitions. | <dl><dt>HTML</dt><dd>Markup language</dd></dl> |
Differences between HTML and XHTML
| Feature | HTML (Traditional) | XHTML (Strict) |
|---|---|---|
| Syntax Rule | Looser, more forgiving. | Strict XML syntax. |
| Case Sensitivity | Tags/attributes not case-sensitive. | Tags/attributes must be lowercase. |
| Closing Tags | Optional for some elements (e.g., <p>). |
All elements must be closed. |
| Attribute Quotes | Quotes around attribute values optional. | Attribute values must be in quotes. |
| Empty Elements | <br>, <img> without closing slash. |
Must be self-closed: <br />, <img /> |
| Nesting | Improper nesting sometimes tolerated. | Must be properly nested. |
[!TIP] Exam Focus: XHTML is essentially HTML rewritten in XML. Key exam points are lowercase tags, quoted attributes, and closed all elements.
2. CSS (Cascading Style Sheets)
Introduction to CSS
-
Purpose: Separates content (HTML) from presentation (styling: layout, colors, fonts).
-
Types:
-
Inline: Style attribute within an HTML tag. (Low reusability).
-
Internal (Embedded):
<style>block within the HTML<head>. -
External: Separate
.cssfile linked via<link>. (Most maintainable & reusable).
-
Advantages of CSS
-
Separation of Concerns: Cleaner, more manageable code.
-
Reusability: One stylesheet can style multiple pages.
-
Maintainability: Change style in one place (CSS file) to update entire site.
-
Reduced Code & Bandwidth: Less repetitive HTML, faster page loads.
-
Accessibility: Better control for different media (print, screen readers).
[!TIP] Common Pitfall: Inline styles have the highest specificity, making them hard to override. Use external CSS for maintainability.
3. JavaScript for Client-Side Interactivity
Form Elements: Radio Buttons and Checkboxes
-
Radio Buttons (
<input type="radio">): Mutually exclusive selection within anamegroup. Access viadocument.formName.radioName.value. -
Checkboxes (
<input type="checkbox">): Allow multiple selections. Access viaelement.checked(boolean) property. -
Validation Example:
if (document.myForm.gender.value === "") { alert("Please select a gender."); return false; }
Document Object Model (DOM)
-
Concept: Programming interface for HTML/XML documents. Represents the page as a tree structure of nodes (objects).
-
Tree Structure:
document(root) →html→head/body→ elements, attributes, text. -
Manipulation Methods (Key Examples):
-
getElementById(id) -
getElementsByClassName(className) -
getElementsByTagName(tagName) -
createElement(tagName) -
appendChild(node) -
innerHTML/textContent
-
[!TIP] Exam Ready: DOM is the bridge between JavaScript and HTML. Know how to select an element and modify its content/style.
4. HTTP Protocol
What is HTTP?
-
Definition: HyperText Transfer Protocol. The foundation of data communication for the World Wide Web.
-
Stateless Protocol: Each request from a client to a server is treated as independent; the server does not retain user session data between requests by default.
-
Request-Response Model: Client (Browser) sends an HTTP Request → Server processes and sends an HTTP Response.
Utility of HTTP
-
Web page, image, and file transfer.
-
Caching: Mechanisms (
Cache-Control,Expires) to store responses and reduce server load. -
Content Negotiation: Client and server can agree on the best representation of a resource (e.g., language, format) via headers like
Accept.
HTTP Methods & Idempotency
| Method | Purpose | Idempotent? | Safe? |
|---|---|---|---|
| GET | Retrieve data (read-only). | Yes | Yes |
| POST | Submit data to be processed (create). | No | No |
| PUT | Update a resource (replace). | Yes | No |
| DELETE | Remove a resource. | Yes | No |
| HEAD | Same as GET but without response body. | Yes | Yes |
\boxed{\text{Idempotent: Multiple identical requests have the same effect as a single request.}} \
\boxed{\text{Safe: Method is read-only and does not modify server state.}}
5. XML (Extensible Markup Language)
Introduction to XML
-
Purpose: To store and transport structured data in a platform-independent, self-descriptive text format. Not for display (unlike HTML).
-
Well-formed vs. Valid:
-
Well-formed: Follows basic XML syntax rules (single root element, proper nesting, closed tags, quoted attributes).
-
Valid: Conforms to a Document Type Definition (DTD) or XML Schema (XSD) that defines allowed elements/attributes.
-
Attributes of XML
-
Self-descriptive: Data and its meaning are stored together.
-
Platform-independent: Text-based, works on any OS.
-
Extensible: Users can define their own tags and structure.
-
Text-based: Human and machine-readable.
XSLT (Extensible Stylesheet Language Transformations)
-
Purpose: To transform an XML document into another format (e.g., HTML, PDF, another XML).
-
Process: Uses an XSLT stylesheet (
.xsl) containing templates and XPath expressions to match and reformat XML data.<!-- Example XSLT snippet to transform XML to HTML --> <xsl:template match="/"> <html><body> <xsl:apply-templates select="book"/> </body></html> </xsl:template>
6. PHP Server-Side Scripting
Loop Statements
| Loop | Syntax | Use Case |
|---|---|---|
for |
for (init; condition; increment) { ... } |
Known number of iterations. |
while |
while (condition) { ... } |
Unknown iterations, check condition first. |
do-while |
do { ... } while (condition); |
Execute at least once. |
foreach |
foreach ($array as $value) { ... } |
Iterate over arrays/objects. |
Object-Oriented Programming in PHP
-
Class: Blueprint/template (
class Car { ... }). -
Object: Instance of a class (
$myCar = new Car();). -
Encapsulation: Bundling data (properties) and methods (functions) together, controlling access via
public,private,protected. -
Inheritance: A class (
Child) extends another (Parent) usingextends, inheriting its properties/methods. -
Constructor: Special method (
__construct()) called automatically when an object is created.
File Handling
-
Basic Steps:
-
Create/Open:
fopen("file.txt", "mode") -
Read/Write:
fread(),fwrite(),fgets() -
Close:
fclose($handle)
-
-
Common File Modes:
-
"r"- Read only. -
"w"- Write (truncates existing file). -
"a"- Append. -
"r+"- Read/Write. -
"x"- Create new (fails if exists).
-
Database Connectivity with MySQL
-
Using
mysqli(Procedural):$conn = mysqli_connect("localhost", "username", "password", "database"); if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } -
Using PDO (Recommended):
try { $conn = new PDO("mysql:host=localhost;dbname=database", "username", "password"); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); }
Creating Database Tables via PHP
$sql = "CREATE TABLE Users (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)";
if ($$\displaystyle conn->query( $$sql) === TRUE) {
echo "Table Users created successfully";
} else {
echo "Error creating table: " . $conn->error;
}
7. Web Forms and State Management
Forms and Form Fields
-
Form Tag:
<form action="process.php" method="post"> ... </form> -
Common Input Fields:
-
<input type="text">- Single-line text. -
<input type="password">- Masked text. -
<input type="radio">- Single choice. -
<input type="checkbox">- Multiple choices. -
<input type="submit">/<button type="submit">- Submit form. -
<textarea>- Multi-line text. -
<select>/<option>- Dropdown list.
-
-
Key Attributes:
name(for server access),value,required,placeholder.
Session vs Cookie
| Feature | Session | Cookie |
|---|---|---|
| Storage Location | Server (file/database). | Client Browser (text file). |
| Lifetime | Ends when browser closes or times out. | Can persist for a defined period (expires). |
| Data Size | Larger (limited by server config). | Small (~4KB). |
| Security | More secure (data not exposed to client). | Less secure (user can see/modify). |
| Usage | Sensitive data (user ID, cart). | Non-critical preferences (theme, language). |
| PHP Start | session_start(); |
setcookie("name", "value", time()+3600); |
\boxed{\text{Sessions store data on the server; Cookies store data on the client.}}
8. Web Design and Development Considerations
Web Design Issues
-
Usability: Intuitive navigation, clear calls-to-action.
-
Accessibility (WCAG): Use semantic HTML, ARIA labels, alt text for images, keyboard navigation.
-
Responsiveness: Design for all devices (mobile-first) using CSS media queries.
-
Cross-Browser Compatibility: Test in Chrome, Firefox, Safari, Edge. Use vendor prefixes if needed.
-
SEO (Search Engine Optimization): Proper use of headings (
<h1>-<h6>), meta tags, clean URLs, fast loading.
Database Bugs (Common Errors & Debugging)
| Bug Type | Description | Debugging Technique |
|---|---|---|
| SQL Injection | Malicious SQL inserted via input fields. | Use prepared statements (mysqli_stmt, PDO). Never concatenate raw input. |
| Connection Issues | Wrong credentials, server down. | Check mysqli_connect_error(), verify DB server status. |
| Syntax Errors | Missing comma, quote, or incorrect SQL. | Echo/Log the final SQL query (echo $sql;) and run it directly in DB tool (phpMyAdmin). |
| Logic Errors | Wrong query, incorrect data handling. | Step-through debugging (Xdebug), var_dump() results. |
| Permission Issues | DB user lacks privileges. | Grant appropriate privileges (GRANT). |
[!TIP] Critical Security Rule: Always use prepared statements with parameterized queries to prevent SQL injection. This is a frequent exam and real-world focus.