What is the Session driver configuration in CodeIgniter 4?
Why Interviewers Ask This
Candidates at the intermediate level are expected to not only know this concept but explain the trade-offs involved. Interviewers use this question to see if you can reason about design decisions, not just recall facts.
Answer
CI4 sessions support four drivers configured in app/Config/Session.php. FileHandler (default): stores session files in writable/session/ — simple but not suitable for multi-server setups. DatabaseHandler: stores sessions in a database table — portable and auditable, configure with $driver = "CodeIgniter\Session\Handlers\DatabaseHandler" and create the sessions table with php spark session:migration. RedisHandler: fastest option for production, supports multiple servers and session expiration natively. MemcachedHandler: similar to Redis. Key settings: $sessionExpiration (seconds of inactivity before expiry), $sessionRegenerateDestroy (whether to delete old session on regeneration), $sessionMatchIP (invalidate session if IP changes — balance between security and usability for mobile users). Use Redis or database sessions in any multi-server production environment.
Pro Tip
Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex CodeIgniter answers easy to follow.