How does session_start() initialize custom $_SESSION variables in PHP?
When using session_start() in PHP, custom $_SESSION variables can be initialized by assigning values to them directly after calling session_start(). This ensures that the variables are available throughout the session for storing and retrieving data specific to the user.
<?php
session_start();
// Initialize custom $_SESSION variables
$_SESSION['username'] = 'JohnDoe';
$_SESSION['email'] = 'johndoe@example.com';
$_SESSION['isLoggedIn'] = true;
?>
Related Questions
- What is the difference between $_SERVER['REMOTE_ADDR'] and $REMOTE_ADDR in PHP?
- What potential pitfalls should be avoided when using PHP's mysql_query function for database operations?
- How can text formatting issues be addressed in PHP forms and what strategies can be implemented to ensure proper display of user input?