Unit 4 Flashcards
Why is the web often referred to as “stateless”?
A. Web pages expire every minute
B. Web servers store all form data permanently
C. Each request is independent — no memory of prior interaction
D. Browsers do not support JavaScript
Answer: C
What PHP function is used to send a cookie to the browser?
A. cookie_start()
B. send_cookie()
C. setcookie()
D. create_cookie()
Answer: C
Where must setcookie() be placed in your PHP file to work properly?
A. Inside the HTML body
B. Before any HTML output is sent
C. After the closing </html> tag
D. Anywhere, PHP parses it anyway
Answer: B
Which PHP superglobal is used to access a cookie’s value?
A. $_COOKIES
B. $_SESSION
C. $_COOKIE
D. COOKIE[]
Answer: C
Which line sets a cookie to expire 1 hour from now?
A. setcookie(‘user’, ‘Ali’);
B. setcookie(‘user’, ‘Ali’, 60);
C. setcookie(‘user’, ‘Ali’, time() + 3600);
D. setcookie(‘user’, ‘Ali’, expire=60);
Answer: C
What does session_start() do?
A. Creates a new server
B. Starts a new browser window
C. Initializes/resumes a session on the server
D. Begins HTML rendering
Answer: C
Which superglobal stores session data in PHP?
A. $_SESSION
B. $_COOKIE
C. $_POST
D. $_STATE
Answer: A
To destroy a PHP session, which of the following is correct?
A. session_close();
B. session_end();
C. session_destroy();
D. destroy_session();
Answer: C
Which of the following is TRUE about sessions vs cookies?
A. Cookies are stored on the server, sessions on the client
B. Cookies can store objects, sessions cannot
C. Sessions are stored on the server and can hold arrays/objects
D. Cookies persist forever; sessions never expire
Answer: C
What does header(“Location: page.php”) do?
A. Adds a navigation bar
B. Redirects the browser to another page
C. Deletes cookies
D. Opens a new browser tab
Answer: B
What causes the common PHP error “headers already sent”?
A. Header function is used twice
B. HTML is echoed before header() is called
C. You forgot require_once()
D. The cookie is expired
Answer: B
How is data passed in a query string to another page?
A. $_POST[“data”]
B. $_SESSION[“data”]
C. $_GET[“data”]
D. $_QUERY[“data”]
Answer: C
What is the purpose of the unset($_SESSION[‘name’]); function?
A. Ends a session completely
B. Deletes a specific session variable
C. Refreshes a cookie
D. Sends a form submission
Answer: B
When does a session variable get deleted automatically?
A. When the user logs out
B. When the page is refreshed
C. When the session expires (inactivity timeout)
D. When the browser is closed
Answer: C
Why would you use hidden form fields instead of query strings?
A. To increase SEO
B. To prevent styling issues
C. To pass values securely via POST, not exposed in URLs
D. To save cookies
Answer: C
How can you manually delete a cookie named firstname in PHP?
A. deletecookie(‘firstname’);
B. unset($_COOKIE[‘firstname’]);
C. setcookie(‘firstname’, ‘’, time() - 3600);
D. clear_cookie(‘firstname’);
Answer: C
What technique is used to auto-fill a form with saved user values using cookies?
A. $_POST
B. JavaScript local storage
C. Retrieving cookie values via $_COOKIE and placing them in form inputs
D. Using hidden fields only
Answer: C
In the mini shop MVC app, what condition is used to check if a user is logged in via session?
A. if ($_COOKIE[‘user’])
B. if ($_SESSION[‘logged_in’])
C. if ($_POST[‘login’])
D. if ($view->user)
Answer: B