What are the best practices for storing and sending JWT tokens in PHP applications?

When storing and sending JWT tokens in PHP applications, it is important to follow best practices to ensure the security of the tokens. One common approach is to store the JWT token securely in a session or a cookie, and then send it in the Authorization header of HTTP requests. This helps prevent the token from being exposed to potential security risks.

// Storing JWT token securely in a session
session_start();
$_SESSION['jwt_token'] = $jwtToken;

// Sending JWT token in Authorization header
$headers = getallheaders();
$jwtToken = $headers['Authorization'];