How can one ensure secure handling of sessions and encryption in PHP?

To ensure secure handling of sessions and encryption in PHP, you can use session_start() to start a secure session, set session.cookie_secure to true to only transmit session cookies over HTTPS, and use functions like password_hash() and password_verify() for secure password hashing and verification.

// Start a secure session
session_start();

// Only transmit session cookies over HTTPS
ini_set('session.cookie_secure', 1);

// Example of using password_hash() and password_verify()
$password = "securepassword123";
$hashed_password = password_hash($password, PASSWORD_DEFAULT);

if (password_verify($password, $hashed_password)) {
    echo "Password is correct";
} else {
    echo "Password is incorrect";
}