What are the advantages and disadvantages of storing user data client-side versus server-side in PHP?

Storing user data client-side in PHP can provide faster access to information and reduce server load, but it also poses security risks as the data is more vulnerable to manipulation by the user. On the other hand, storing data server-side ensures better security and control over the information, but it may result in slower performance due to the need to fetch data from the server.

// Storing user data server-side
session_start();

// Set user data in session
$_SESSION['user_id'] = 123;
$_SESSION['username'] = 'john_doe';

// Access user data from session
$user_id = $_SESSION['user_id'];
$username = $_SESSION['username'];

// Destroy session data when no longer needed
session_destroy();