How can the session_start() function be used to initiate a session in PHP?

To initiate a session in PHP, you can use the session_start() function at the beginning of your PHP script. This function creates a new session or resumes an existing one based on a session identifier passed via a GET or POST request, or a cookie. It is essential to call session_start() before accessing any session variables or using session-related functions.

<?php
// Start a new or resume an existing session
session_start();

// Access session variables or set new ones
$_SESSION['username'] = 'john_doe';
$_SESSION['user_id'] = 12345;
?>