Google News
logo
PHP Program to Get session variable values
To get the value of a session variable in PHP, you can use the `$_SESSION` superglobal array. This array contains all the session variables and their values.

Here's an example program that sets a session variable and then retrieves its value :
Program :
<?php
// Start the session
session_start();

// Set a session variable
$_SESSION['username'] = 'john';

// Get the session variable value
$username = $_SESSION['username'];

// Print the variable value
echo "Username: $username";
?>
Output :
Username: john
In this program, we start the session using the `session_start()` function. We then set a session variable named `username` to the value `'john'`. Finally, we retrieve the value of the `username` variable from the `$_SESSION` array and print it to the screen using `echo`.

Note that in order to use session variables, you must call `session_start()` at the beginning of your program, before any output is sent to the browser. Also, you should avoid using sensitive information as session variable names or values.