Blog Testing
Explanation:
- Start the Session: Each file starts the session with session_start(). This function must be called before any output is sent to the browser.
- Login and Set Session: In index.php, after the user submits the form, a session variable user_id is set and the user is redirected to dashboard.php.
- Check Session and Display Session ID: In dashboard.php, the script checks if user_id is set in the session. If not, it redirects to the login page. If the session is valid, it retrieves and displays the session ID and user ID.
- Logout and Destroy Session: In logout.php, the session is destroyed and the user is redirected to the login page.
This structure ensures that the session is checked at the start of each script, providing a secure way to manage user sessions.