on-internet
← Community

What is the correct way to structure a PHP session login with PRG, CSRF token and inactivity timeout (without a database)?

Stack Overflow ·

What the code does Starts the session with use_strict_mode, cookie_httponly and cookie_samesite=Lax. Login against a hard-coded user array using password_hash() / password_verify(), with the same error message for a wrong user or a wrong password. Calls session_regenerate_id(true) right after a successful login to prevent session fixation. Stores only the user's login and display name in $_SESSION (never the password or hash). Expires the session after 10 minutes of inactivity by storing a ultima_actividad timestamp, checked on every request. Generates a CSRF token with random_bytes(), include

Comments

Sign in or sign up to comment and upvote.

No comments yet.