Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
PHP 10 questions

Sessions, Cookies & State Management

Master stateless protocol state management. Secure and handle user sessions, cookies, session hijacking, and CSRF protection.

More PHP
Interview questions 1–10 of 10
1

What is the difference between sessions and cookies in PHP?

Both are ways to persist data across HTTP requests, but they store data in different places and serve differen...

Read answer →
2

How do you start and use sessions in PHP?

Call session_start() at the very beginning of your script (before any output).session_start(); if (isset($_POS...

Read answer →
3

What is session fixation and how do you prevent it?

Session fixation is when an attacker forces a user to use a known session ID. Prevent it by regenerating the s...

Read answer →
4

How do you set and retrieve cookies in PHP?

setcookie('user_preference', 'dark_mode', [ 'expires' => time() + (30 * 24 * 60 * 60), 'secure' => tru...

Read answer →
5

What is the difference between session_destroy() and session_unset()?

FunctionWhat it doessession_unset()Clears $_SESSION values onlysession_destroy()Deletes entire session file

Read answer →
6

How do you configure session handling in php.ini?

DirectivePurposesession.save_handlerWhere to store sessionssession.gc_maxlifetimeSession timeout in secondsses...

Read answer →
7

What is session hijacking and how do you prevent it?

Session hijacking is when an attacker steals a valid session ID. Prevent by using HTTPS, httponly flag, and re...

Read answer →
8

How do you implement remember-me functionality?

Store a secure token in database and set a long-lived cookie. On subsequent visits, validate the token before...

Read answer →
9

How do you prevent CSRF attacks?

CSRF happens when an attacker makes a user unknowingly send requests. Main defense is a CSRF token in forms.if...

Read answer →
10

How do you use cookies with different domains and paths?

setcookie('admin_token', $token, [ 'path' => '/admin', 'secure' => true, 'httponly' => true ]); se...

Read answer →