PHP/Cookie Session/session start
Содержание
Encode all session data into a single string and return the result
<source lang="html4strict">
<?php
session_start(); $_SESSION["username"] = "jason"; $_SESSION["loggedon"] = date("M d Y H:i:s"); $sessionVars = session_encode(); echo $sessionVars;
?>
</source>
<?php session_start(); ?>
<source lang="html4strict">
<html>
<head> <title>Session still running</title> <style type = "text/css"> body { font-family:<?php echo( $_SESSION["font"] ); ?>; } </style> </head> <body>
Preferred font family is still <?php echo( $_SESSION["font"] ); ?>
<a href="prefs1.php">Change font?</a> </body>
</html>
</source>
Session running
<source lang="html4strict">
<?php session_start(); ?>
<html>
<head> <title>Session running</title> <style type="text/css"> body { font-family:<?php echo $_SESSION["font"]; ?> } </style> </head> <body>
Preferred font family is <?php echo $_SESSION["font"]; ?>
<a href="prefs3.php?<?php echo( SID ); ?>">Next page</a> </body>
</html>
</source>
session_start() checks to see if a session has started, and if not, it starts one.
<source lang="html4strict">
Its syntax is: boolean session_start() <? session_start(); ?>
</source>
Session starter
<source lang="html4strict">
<?php session_start(); ?> <html>
<head> <title>Session starter</title> <head> <body> <a href="next.php?<?php echo( SID ); ?>">Next page</a>
PHPSESSID = <?php echo ( session_id() ); ?> </body>
</html>
</source>
Sessions with register_globals on or off in session_test.php
<source lang="html4strict">
<?php session_start( ); if (isset($username)) {
$username=htmlentities($username); echo "Hello $username";
} else {
echo "Please login.";
} ?>
</source>