Master Server-Side Scripting (PHP) Class 12 IT (Science) Chapter 5 with complete, latest-syllabus-verified Maharashtra State Board (MSBSHSE) Balbharati exercise solutions. This comprehensive study guide includes all textbook questions—Fill in the Blanks, True or False, Multiple Choice Questions (MCQs), Answer in Brief, and PHP Form Programs—along with board-exam-style 2-correct and 3-correct MCQs, Match the Following, core PHP concepts, superglobals, string and array functions, and practical SOP-ready code examples.
Key PHP Syntax, Superglobals, Functions & Concepts – Chapter 5 Overview
PHP (Hypertext Preprocessor) is a widely used open-source, server-side scripting language embedded inside HTML to build dynamic web pages and process HTML forms securely on a web server. Unlike client-side JavaScript, PHP scripts are executed by the server interpreter (such as Apache with PHP), and only plain HTML output is delivered to the client’s browser. Before reviewing the textbook exercise answers, revise the essential PHP syntax elements, data types, superglobal arrays, and built-in functions summarized below.
| PHP Element / Keyword | Category | Purpose & Board Exam Significance |
|---|---|---|
<?php ... ?> |
PHP Delimiter Tags | Encloses PHP server-side code inside an HTML document; files are saved with the .php extension. |
echo / print |
Output Statements | Outputs strings, HTML markup, or variable values directly into the generated web page response. |
$variable_name |
Variables & Scope | Variables always begin with $, are case-sensitive, and support local, global, and static scopes. |
| String, Integer, Float, Boolean, Array, NULL | Supported Data Types | PHP is loosely typed, automatically assigning data types based on the value stored in a variable. |
$_GET |
Superglobal Array | Collects form data sent via the HTTP GET method as visible URL query parameters; never use for passwords. |
$_POST |
Superglobal Array | Collects form data sent invisibly inside the HTTP request body; suitable for sensitive data and larger payloads. |
isset() |
Variable Check Function | Determines whether a form field or variable is declared and not NULL before processing submission. |
strlen(), str_word_count() |
String Functions | strlen() returns total characters in a string; str_word_count() counts the number of words. |
strrev(), strpos(), substr() |
String Functions | strrev() reverses a string; strpos() finds text position; substr() extracts part of a string. |
| Indexed, Associative & Multidimensional | PHP Arrays | Arrays store multiple values in a single variable using numeric keys (indexed) or named keys (associative). |
function name($arg) |
User-Defined Functions | Reusable blocks of code that accept information through arguments and optionally return computed values. |
$_SESSION & $_COOKIE |
State Management | Maintain user state across multiple web pages using server-side session storage or client-side cookies. |
Balbharati Textbook Exercise Solutions – Chapter 5: Server-Side Scripting (PHP)
Below are the complete, syllabus-accurate solutions to every question in the Maharashtra State Board Class 12 Information Technology (Science) Balbharati textbook exercise for Chapter 5.
Q.1. Fill in the Blanks
| Q. No. | Textbook Statement | Correct Answer |
|---|---|---|
| 1 | PHP is _________ side scripting language. | Server |
| 2 | PHP is _________ language i.e. there is no need for compilation. | interpreted |
| 3 | A variable starts with _________ sign followed by variable name. | $ |
| 4 | An _________ is a variable, which can hold more than one value at a time. | array |
| 5 | Information can be passed to functions through _________. | arguments |
Q.2. State Whether the Following Statements Are True or False
| Q. No. | Textbook Statement | Answer & Explanation |
|---|---|---|
| 1 | PHP is platform dependent scripting language. | False — PHP is platform-independent and runs reliably across Windows, Linux, macOS, and Unix web servers. |
| 2 | $_POST is an array of variables passed via the URL parameters. |
False — Variables passed via URL parameters are collected in $_GET, whereas $_POST sends form variables inside the HTTP request body. |
| 3 | A Function is a block of statements that can be used repeatedly in a program. | True — User-defined and built-in functions promote modularity and code reuse without rewriting identical statements. |
| 4 | PHP cannot be embedded along with HTML tags. | False — PHP blocks enclosed inside <?php ... ?> can be seamlessly embedded anywhere inside HTML documents. |
| 5 | GET should NEVER be used for sending sensitive information. | True — The GET method appends form values directly to the URL in plain text, making passwords and private data visible in browser history and server logs. |
Q.3. Multiple Choice Questions (Select One Correct Answer)
| Q. No. | Textbook Question | Correct Option | Explanation |
|---|---|---|---|
| 1 | The program file of PHP has ______ extension. a) .asp b) .php c) .js d) .text |
b) .php |
A web server recognizes and executes embedded PHP scripts only when the file is saved with the .php extension (.asp is Active Server Pages and .js is JavaScript). |
| 2 | A variable declared ______ a function has global scope. a) outside b) anywhere c) inside d) none |
a) outside | A variable defined outside all functions belongs to the global scope and can only be accessed outside functions unless brought inside using the global keyword or $GLOBALS array. |
Board Exam Practice: Multi-Select MCQs, True/False & Match the Following
In the MSBSHSE Class 12 IT online board examination, students face additional question formats including Single-Correct MCQs, Two-Correct MCQs, Three-Correct MCQs, and Match the Following / Rearrange items drawn from the Chapter 5 syllabus. Use the syllabus-aligned practice tables below to strengthen accuracy across every exam section.
Practice Set A: Extra Syllabus Fill in the Blanks & Single-Correct MCQs
| Format | Practice Question | Correct Answer & Reason |
|---|---|---|
| Fill in the Blank | PHP stands for _________. | Hypertext Preprocessor — Originally named Personal Home Page, PHP is now a recursive acronym for Hypertext Preprocessor. |
| Fill in the Blank | Every PHP statement ends with a _________. | semicolon (;) — PHP requires a semicolon at the end of each statement to separate instructions cleanly. |
| Fill in the Blank | The _________ function returns the total number of characters present in a string. | strlen() — Spaces and punctuation marks are also counted as characters by strlen(). |
| MCQ (1 Correct) | Which superglobal array collects form data sent with method="get"?a) $_POST b) $_GET c) $_SERVER d) $_SESSION |
b) $_GET — Data submitted via HTTP GET is appended to the URL query string and stored in the associative $_GET array. |
| MCQ (1 Correct) | Which operator is used in PHP to join (concatenate) two strings? a) + b) & c) . d) * |
c) . (Dot operator) — Unlike JavaScript which uses +, PHP uses the dot (.) operator for string concatenation. |
Practice Set B: Multiple Choice Questions (Two & Three Correct Options)
| Question Type | Practice Statement | Correct Answers & Justification |
|---|---|---|
| MCQ (2 Correct) | Which two statements are true about PHP? a) PHP scripts execute on the server computer b) PHP requires manual compilation into .exe before runningc) PHP is open-source and platform-independent d) PHP source code is directly visible in “View Page Source” |
a) and c) — PHP is an open-source, cross-platform, interpreted language that runs on the server and outputs only HTML to the browser. |
| MCQ (2 Correct) | Which two superglobal variables are primarily used in PHP to collect HTML form data? a) $_GETb) $_ECHOc) $_POSTd) $_PRINT |
a) and c) — $_GET and $_POST are built-in PHP superglobal arrays used to retrieve submitted form inputs. |
| MCQ (2 Correct) | Identify two valid rules for naming PHP variables: a) A variable name must start with $ followed by a letter or underscoreb) A variable name can start with a digit like $1valuec) PHP variable names are case-sensitive d) Variable names can contain spaces |
a) and c) — Valid variables start with $ plus a letter or _, allow only alphanumeric characters and underscores, and treat uppercase and lowercase letters differently. |
| MCQ (3 Correct) | Select three valid PHP data types: a) String b) Integer c) Character d) Boolean e) Unsigned Long |
a), b), and d) — String, Integer, Float, Boolean, Array, and NULL are standard PHP data types; PHP does not have separate Character or Unsigned Long types. |
| MCQ (3 Correct) | Which three are built-in PHP string manipulation functions? a) strlen()b) str_word_count()c) charAt()d) strrev()e) toUpperCase() |
a), b), and d) — strlen(), str_word_count(), and strrev() are PHP string functions, whereas charAt() and toUpperCase() belong to JavaScript. |
| MCQ (3 Correct) | Which three array types are supported in PHP? a) Indexed array b) Associative array c) Multidimensional array d) Static-pointer array e) Bitwise array |
a), b), and c) — PHP supports indexed arrays (numeric indices), associative arrays (named keys), and multidimensional arrays (arrays containing arrays). |
Practice Set C: Match the Following & Statement Rearranging
| Column A | Column B (Jumbled) | Correct Match |
|---|---|---|
1. strlen() |
a) Collects form values invisibly in HTTP body | 1 → c) Returns total character length of a string |
2. $_POST |
b) Reverses all characters in a string | 2 → a) Collects form values invisibly in HTTP body |
3. strrev() |
c) Returns total character length of a string | 3 → b) Reverses all characters in a string |
4. $_GET |
d) Passes form inputs as URL query parameters | 4 → d) Passes form inputs as URL query parameters |
5. array() |
e) Creates a variable holding multiple values | 5 → e) Creates a variable holding multiple values |
Rearrange the Steps for Executing a PHP Form Program: Arrange the sequence in logical execution order: (A) Server executes PHP script and generates HTML output → (B) User fills the HTML form and clicks Submit → (C) Browser renders the final HTML response → (D) Web server receives HTTP request with $_POST or $_GET data.
Correct Order: (B) → (D) → (A) → (C).
Q.6. Answer in Brief – Complete Textbook Solutions
Present answers in clear, numbered bullet points during the Maharashtra State Board Class 12 IT examination to earn full marks. Below are complete answers to all descriptive textbook questions from Chapter 5.
1) Explain any two features of PHP?
Answer:
Two important features of PHP are explained below:
- Simple: PHP is very simple and easy to learn compared to many other server-side scripting languages. Its syntax resembles C and Java, allowing beginners to write dynamic web scripts quickly.
- Interpreted: PHP is an interpreted language, which means there is no need for a separate compilation step before running the code. The PHP engine on the web server reads and executes the script line by line at runtime.
(Additional valid textbook features include: Faster execution than many traditional scripting languages, Open Source free availability under the PHP license, Platform Independent support across Windows/Linux/macOS, and Case-Sensitive variable naming.)
2) What are the rules for declaring variables in PHP?
Answer:
The standard rules for declaring variables in PHP are:
- A variable name must always start with the dollar sign (
$), followed by the name of the variable (for example,$marks). - A variable name must begin with a letter (
a–z,A–Z) or an underscore (_) character. - A variable name cannot start with a number (for example,
$1nameis invalid). - A variable name can only contain alpha-numeric characters and underscores (
A–z,0–9, and_); spaces and special symbols are not allowed. - Variable names in PHP are case-sensitive, meaning
$ageand$AGEare treated as two completely separate variables.
3) What is server-side scripting?
Answer:
- Server-side scripting is a web development technique in which scripts are executed on a remote web server rather than on the user’s client browser.
- When a user submits a request or form from a web page, the web server processes the server-side script (written in PHP, Python, ASP.NET, or JSP), performs business logic or database operations if required, and builds a dynamic HTML output.
- The resulting plain HTML page is sent back to the client browser, keeping the underlying source code and database credentials secure on the server.
4) List the supported data types in PHP.
Answer:
PHP supports the following built-in data types to store different kinds of values:
- String: A sequence of characters enclosed within single or double quotes (e.g.,
"Maharashtra Board"). - Integer: Non-decimal whole numbers, either positive or negative (e.g.,
100,-25). - Float (Floating-point / Double): Numbers containing a decimal point or written in exponential notation (e.g.,
98.6). - Boolean: Represents one of two logical truth states—
TRUEorFALSE. - Array: A composite variable capable of storing multiple values under indexed or named keys.
- NULL: A special data type having only one value,
NULL, indicating a variable with no assigned value.
5) Explain any two string manipulation functions.
Answer:
strlen(): This function returns the total length of a given string, counting all letters, digits, spaces, and special characters.
Example:echo strlen("Hello PHP");outputs9.str_word_count(): This function counts and returns the total number of words present in a given string.
Example:echo str_word_count("Server Side Scripting");outputs3.
(Other syllabus string functions include strrev() to reverse text, strpos() to search for text inside a string, and substr() to extract a substring.)
Q.7. Write Programs for the Following – Textbook PHP Coding Solutions
Below are the complete, tested solutions for all three programming questions in the Balbharati Chapter 5 textbook exercise. Save each file with a .php extension inside your local server directory (such as htdocs in XAMPP) and access it through localhost.
1) Write a PHP code which calculates the square of any number using a form.
This single-file PHP program renders an HTML form using method="post", checks whether the form was submitted via isset($_POST['submit']), and prints the square of the entered number.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Square of a Number in PHP</title>
</head>
<body>
<h2>Square Calculator</h2>
<form method="post" action="">
Enter a Number: <input type="number" name="sq" required><br><br>
<input type="submit" name="submit" value="Calculate Square">
</form>
<?php
if (isset($_POST['submit'])) {
$num = $_POST['sq'];
$square = $num * $num;
echo "<p>The square of <strong>" . htmlspecialchars($num) . "</strong> is: <strong>" . $square . "</strong></p>";
}
?>
</body>
</html>
2) Write a PHP code to count the number of words in a given string.
This program accepts any sentence or phrase from the user and computes the total word count using PHP’s built-in str_word_count() function.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Word Counter in PHP</title>
</head>
<body>
<h2>Count Words in a String</h2>
<form method="post" action="">
Enter a String: <input type="text" name="str" size="40" required><br><br>
<input type="submit" name="submit" value="Count Words">
</form>
<?php
if (isset($_POST['submit'])) {
$text = $_POST['str'];
$wordCount = str_word_count($text);
echo "<p>Entered String: <strong>" . htmlspecialchars($text) . "</strong></p>";
echo "<p>Total Number of Words: <strong>" . $wordCount . "</strong></p>";
}
?>
</body>
</html>
3) Create a website with two PHP web pages connected to each other. The first page contains two form fields for taking ‘name’ and ‘password’ from users. On the submit event, details of the form should be displayed on the second web page.
Notice that the action="display.php" attribute in the first file connects the form submission to the second PHP page, while method="post" protects sensitive password values from appearing in the URL.
Page 1: form.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>User Login Form</title>
</head>
<body>
<h2>Enter User Details</h2>
<form action="display.php" method="post">
Enter Name: <input type="text" name="name" required><br><br>
Enter Password: <input type="password" name="pass" required><br><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
Page 2: display.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Display Form Details</title>
</head>
<body>
<h2>Submitted User Details</h2>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = htmlspecialchars($_POST["name"]);
$password = htmlspecialchars($_POST["pass"]);
echo "Welcome, <strong>" . $username . "</strong><br>";
echo "Entered Password: <strong>" . $password . "</strong>";
}
?>
</body>
</html>
Bonus SOP Practice Program: Check Voter Eligibility Using PHP Conditional Statements
Practical SOPs for Chapter 5 frequently test if...else branching with HTML forms. Study this concise age-verification script for practical exam preparation.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Voter Eligibility Check</title>
</head>
<body>
<h2>Check Voting Eligibility</h2>
<form method="post" action="">
Enter Age: <input type="number" name="age" min="1" required><br><br>
<input type="submit" name="check" value="Check Eligibility">
</form>
<?php
if (isset($_POST['check'])) {
$age = (int)$_POST['age'];
if ($age >= 18) {
echo "<p>Age $age: You are eligible to vote.</p>";
} else {
echo "<p>Age $age: You are not eligible to vote.</p>";
}
}
?>
</body>
</html>
Frequently Asked Questions – Science Ch 5 Server-Side Scripting (PHP)
Why should $_POST be used instead of $_GET for login or password forms?
The $_GET superglobal reads data appended directly to the browser URL query string, exposing usernames, passwords, and personal details in the address bar, browser history, and server access logs. In contrast, $_POST transmits form data inside the HTTP request body, keeping inputs hidden from the URL and supporting larger data sizes.
Can a PHP file execute if opened directly by double-clicking it in a browser?
No. Because PHP is a server-side scripting language, a web browser alone cannot interpret <?php ... ?> code. You must place the .php file inside a web server environment (such as XAMPP, WAMP, or Apache with PHP installed) and access it via http://localhost/filename.php so the server processes the PHP script and returns HTML.
What is the difference between echo and print in PHP, and how are variables included in output?
Both echo and print output data to the browser. echo has no return value, can accept multiple comma-separated arguments, and is slightly faster, while print returns 1 and takes a single argument. Inside double quotes (e.g., echo "Hello $name";), PHP automatically expands variable values, whereas single quotes output variable names literally unless joined with the dot (.) concatenation operator.