Skip to content
PHP Logo

How does Mod Rewrite affect the behavior of session_regenerate_id(true) in PHP applications?

Mod Rewrite can affect the behavior of session_regenerate_id(true) in PHP applications by causing the session ID to change unexpectedly due to URL rewriting. To solve this issue, you can add a condition to check if the request is coming from a rewritten URL and exclude session regeneration in those cases.

php
if (!empty($_SERVER['HTTP_X_REWRITE_URL'])) {
    session_regenerate_id(false);
} else {
    session_regenerate_id(true);
}