How to use PHP Session.
Start with start_session() command. It needs to be include on every PHP page that will use session. You can pass the variables between PHP pages using the global $_SESSION variable. When you are done with the session, unset the $_SESSION variable and call session_destroy() command.
page1.php
<?php
start_session();
$_SESSION['valid_user'] = 'Me';
?>
page2.php
<?php
start_session();
if ( isset($_SESSION['valid_user'] ) {
print 'hello ' . $_SESSION['valid_user'];
} else {
print 'hello nobody';
}
// close session
// don't do this: $_SESSION = array();
unset($_SESSION['valid_user'];
session_destroy();
}
?>
No comments:
Post a Comment