What is the correct syntax for setting session variables in PHP?
To set session variables in PHP, you need to start the session using session_start() and then use the $_SESSION superglobal array to assign values to specific keys. This allows you to store data that can be accessed across different pages during a user's session on the website.
<?php
session_start();
// Set session variables
$_SESSION['username'] = 'john_doe';
$_SESSION['email'] = 'john.doe@example.com';
?>
Keywords
Related Questions
- What steps should be taken to ensure that the correct character encoding is maintained throughout the data retrieval and display process in PHP applications using MySQL databases?
- How can PHP be used to create dynamic dropdown menus based on MySQL data?
- Are there any potential pitfalls in using global variables in PHP scripts?