CodShot
PHP Public

Regenerate Session After Login

Regenerate the PHP session ID after a successful login.

#php #session #auth #security
PHP
<?php

session_start();

// After checking the username and password successfully:
session_regenerate_id(true);

$_SESSION['client_id'] = $client['id'];
$_SESSION['client_email'] = $client['email'];
$_SESSION['logged_in_at'] = time();

Notes

Session regeneration helps protect against session fixation attacks.

Snippet actions

CodShot user
CodShot user
Updated: 2026-06-08 14:33
Public snippets
0
Forks
CodShot AI Help
Ask about CodShot features, plans, workspace, AI limits, referrals, and public help topics.
Hi! I can help you understand how CodShot works. What would you like to know?
For account-specific or sensitive issues, please open a support ticket. Open support