What are the potential security risks of using cookies for session management in PHP?

Using cookies for session management in PHP can pose security risks such as session hijacking, session fixation, and information leakage. To mitigate these risks, it is recommended to use PHP's built-in session handling functions to store session data securely on the server side.

<?php
// Start a secure session
session_start();

// Set session variables
$_SESSION['user_id'] = 123;
$_SESSION['username'] = 'john_doe';

// Use session variables in your application
echo 'Welcome, ' . $_SESSION['username'];

// Destroy the session when the user logs out
session_destroy();
?>