Skip to main content

Web Application Development MCQs with Answers

Practice important Web Application Development MCQs with answers and explanations.

Chapter: 7
Q81:
What will be the output of <?php setcookie("user", "Ahmed"); echo $_COOKIE["user"]; ?> after setting the cookie?
A. Ahmed
B. Empty
C. "user"
D. Error
Correct Answer: A
Chapter: 7
Q82:
What happens if you use setcookie() with an expiration date in the past?
A. The cookie is deleted
B. The cookie value is unchanged
C. The cookie value is modified
D. An error occurs
Correct Answer: A
Chapter: 7
Q83:
Fill in the blank: To check if cookies are enabled, count the number of elements in the _______.
A. $_COOKIE
B. $_SESSION
C. $_POST
D. $_GET
Correct Answer: A
Chapter: 7
Q84:
What is the output of <?php date_default_timezone_set("Asia/Karachi"); echo date("h:i:sa"); ?>?
A. The current time in Asia/Karachi timezone
B. The current time in GMT
C. An error message
D. The time in UTC
Correct Answer: A
Chapter: 7
Q85:
Fill in the blank: The setcookie() function must be called _______ the <html> tag.
A. before
B. after
C. during
D. at the end
Correct Answer: A
Chapter: 7
Q86:
What will be the output of <?php $cookie_name = "user"; setcookie($cookie_name, "Ahmed", time() - 3600); ?>?
A. Cookie 'user' is deleted
B. Cookie 'user' is set
C. Error
D. No output
Correct Answer: A
Chapter: 7
Q87:
Fill in the blank: The date() function can format time using characters like h, i, and s for _______.
A. hours, minutes, seconds
B. dates and years
C. day of the week
D. URL encoding
Correct Answer: A
Chapter: 8
Q88:
What function is used to start a session in PHP?
A. session_start()
B. start_session()
C. begin_session()
D. init_session()
Correct Answer: A
Chapter: 8
Q89:
Fill in the blank: Session variables in PHP are stored in _______ and are used across several pages.
A. the server
B. the user’s computer
C. a database
D. a file
Correct Answer: A
Chapter: 8
Q90:
How do you access session variable values on a new page?
A. Use $_SESSION global variable
B. Use session_get()
C. Use session_value()
D. Use get_session()
Correct Answer: A
Chapter: 8
Q91:
Fill in the blank: The session_start() function must be the _______ thing in your PHP document.
A. first
B. last
C. middle
D. optional
Correct Answer: A
Chapter: 8
Q92:
What is the purpose of the session_unset() function in PHP?
A. To remove all session variables
B. To destroy the session
C. To set new session variables
D. To start a new session
Correct Answer: A
Chapter: 8
Q93:
Fill in the blank: The session_destroy() function is used to _______ the session.
A. remove all global session variables
B. modify session variables
C. create a new session
D. retrieve session information
Correct Answer: A
Chapter: 8
Q94:
What does the session_start() function do?
A. Initializes a new session or resumes an existing one
B. Ends a session
C. Deletes all session variables
D. Sets session cookies
Correct Answer: A
Chapter: 8
Q95:
What will happen if session_start() is not the first thing in your document?
A. It will cause an error
B. It will initialize a new session
C. It will retrieve session variables
D. It will destroy the existing session
Correct Answer: A
Chapter: 8
Q96:
Fill in the blank: When a session is opened, PHP looks for a _______ to access the existing session.
A. user-key
B. session-file
C. session-cookie
D. database record
Correct Answer: A
Chapter: 8
Q97:
What function is used to print all session variables for debugging?
A. print_r($_SESSION)
B. debug_session()
C. show_session()
D. list_session()
Correct Answer: A
Chapter: 8
Q98:
Fill in the blank: To ensure session variables are available on multiple pages, they must be set using _______.
A. $_SESSION
B. session_set()
C. session_value()
D. global_session()
Correct Answer: A
Chapter: 8
Q99:
What will be the effect of session_destroy() if used without session_unset()?
A. Session variables will be removed but session will remain
B. Session variables will be retained
C. Only the session cookie will be deleted
D. Nothing will happen
Correct Answer: A
Chapter: 8
Q100:
Fill in the blank: To modify session variables, you simply _______ them using the $_SESSION global variable.
A. reassign
B. delete
C. list
D. print
Correct Answer: A

Test Your Knowledge

Take a timed quiz on Web Application Development

🚀 Start Quiz Now