Server Side Scripting using PHP is an important chapter of Information Technology (IT) for HSC Class 12 Maharashtra Board (MSBSHSE). This chapter helps students understand how dynamic websites work using PHP, forms, sessions, cookies, and database connectivity.
Server Side Scripting PHP Class 12 Exercise Solutions
Q.1 Fill in the blanks.
1. PHP is _ side scripting language.
Show Answer ⟶2. PHP is _ language i.e. there is no need for compilation.
3. A variable starts with __ sign followed by variable name.
Show Answer ⟶4. An __ is a variable, which can hold more than one value at a time.
5. Information can be passed to functions through __
Show Answer ⟶Q2. State True/False.
1. PHP is platform dependent scripting language.
2. $_POST is an array of variables passed via the URL parameters.
Show Answer ⟶3. A Function is a block of statements that can be used repeatedly in a program.
Show Answer ⟶4. PHP cannot be embeded along with HTML tags.
Show Answer ⟶5. GET should NEVER be used for sending sensitive information.
Show Answer ⟶Q3. Multiple Choice Question. (1 correct)
1. The program file of PHP have __ extension.
a) .asp
b) .php
c) .js
d) .txt
2. A variable declared __ a function has global scope.
a) outside
b) anywhere
c) inside
d) none
3. The __ function returns a part of a string.
a) trim()
b) ucwords()
c) substr()
d) strpos()
Q4. Multiple Choice Question. (2 correct)
1. The & _ are valid datatype in PHP.
a) Double
b) Varchar
c) Integer
d) Array
e) BigInt
2. Single line comment in PHP is possible using , _.
a) //
b) /* */
c) #
d)
e) $
Q5. Multiple Choice Question. (3 correct)
1. In PHP, three types of arrays are , _, _ .
a) Indexed
b) Simple
c) Associative
d) Multidimensional
e) Complex
f) General
2. The scope of variable can be __.
a) local
b) global
c) universal
d) static
e) final
f) outside
Q6. Brief Questions.
1) Explain any two features of PHP?
Answer: The two features of PHP is:
- It open source software means it is freely available and widely supported by a large community.
- PHP code can easily embedded within HTML pages which make it simple to use.
2) What are the rules to declare variable in PHP?
Answer: The rules for declaring variable in PHP are:
- A variable name must start with a $ sign.
- It must begin with a letter or underscore, not a number.
- Variable names are case‑sensitive ($name and $Name are different).
- No spaces or special characters are allowed except underscore (_).
3) What is server side scripting?
Answer: The PHP is server side scripting language, it means that the code runs on the web server not on the user browser. This helps to create dynamic content generation, database interaction and secure operation.
4) List the supported datatypes in PHP.
Answer: Variables can store data of different types and PHP supports the following data types :
- String
- Integer
- Float
- Boolean
- Array
- NULL
5) Explain any two string manipulation function.
Answer: The two string manipulation function are:
- substr(): Returns a portion of a string. Example: substr(“Hello World”, 0, 5) → “Hello”.
- trim(): Removes whitespace (or other specified characters) from the beginning and end of a string. Example: trim(” Hello “) → “Hello”.
Q7. Write Programs for the following.
1) Write a PHP code which calculates square of any number using form.
Answer:
<!DOCTYPE html>
<html>
<head>
<title>Square Calculator</title>
</head>
<body>
<form method="post">
Enter a number: <input type="text" name="num">
<input type="submit" value="Calculate Square">
</form>
<?php
if ($_POST) {
$n = $_POST['num'];
$square = $n * $n;
echo "Square of $n is: $square";
}
?>
</body>
</html>2) Write a PHP code to count no. of words in the given string.
Answer:
<!DOCTYPE html>
<html>
<head>
<title>Word Counter</title>
</head>
<body>
<form method="post">
Enter a string: <input type="text" name="str">
<input type="submit" value="Count Words">
</form>
<?php
if ($_POST) {
$text = $_POST['str'];
$count = str_word_count($text);
echo "Number of words in the string: $count";
}
?>
</body>
</html>3) Create a website with two PHP webpage in which each webpage is connected. The first page of the website contains two form fields for taking ‘name’ and ‘password’ from users. On onclick event, details of forms should be displayed on second webpage.
Answer:
Page 1: form.php
<!DOCTYPE html>
<html>
<head>
<title>User Login</title>
</head>
<body>
<form action="display.php" method="post">
Name: <input type="text" name="name"><br><br>
Password: <input type="password" name="password"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>Page 2: display.php
<!DOCTYPE html>
<html>
<head>
<title>Display Details</title>
</head>
<body>
<?php
if ($_POST) {
$name = $_POST['name'];
$password = $_POST['password'];
echo "<h2>User Details</h2>";
echo "Name: " . $name . "<br>";
echo "Password: " . $password;
}
?>
</body>
</html>Disclaimer: We have provide you with the accurate handout of “Server Side Scripting PHP Class 12 Exercise Solutions“. If you feel that there is any error or mistake, please contact me at anuraganand2017@gmail.com. The above study material present on our websites is for education purpose, not our copyrights.
All the above content and Screenshot are taken from Information Technology Class 12 Textbook and MSBSHSE (HSC) Support Material which is present in MSBSHSE (HSC) website, This Textbook and Support Material are legally copyright by Maharashtra State Bureau of Textbook Production and Curriculum Research, Pune. We are only providing a medium and helping the students to improve the performances in the examination.
Images and content shown above are the property of individual organisations and are used here for reference purposes only. To make it easy to understand, some of the content and images are generated by AI and cross-checked by the teachers. For more information, refer to the official website.