Q.10 In PHP, how do you securely access a form value sent via POST to prevent XSS attacks?
A. Using htmlspecialchars($_POST[‘value’])
B. Using $_POST[‘value’] directly
C. Using strip_tags($_POST[‘value’])
D. Using mysqli_real_escape_string($_POST[‘value’])
Answer. A
Q.11 What will be the output of the following PHP code if a user submits a form with an input named email?
if (isset($_POST[’email’])) {
echo $_POST[’email’];
}
?>
A. The value of the email input field
B. NULL
C. An empty string
D. An error message
Answer. A
Q.12 Given a form with method=”post”, which PHP array will contain the form’s submitted data?
A. $_GET
B. $_POST
C. $_REQUEST
D. $_SERVER
Answer. B
Q.13 Which attribute in a form input element specifies the field’s initial value?
A. value
B. type
C. name
D. placeholder
Answer. B
Q.14 What is the correct way to check if a form has been submitted in PHP?
A. Checking if $_POST is set
B. Checking if $_GET is set
C. Checking if $_SERVER[‘REQUEST_METHOD’] is POST
D. Checking if $_REQUEST is set
Answer. C
Q.15 How do you access form data sent via the GET method in PHP?
A. Using the $_REQUEST superglobal
B. Using the $_GET superglobal
C. Using the $_POST superglobal
D. Using the $_SERVER superglobal
Answer. B