1 Maintaining user information in the site through SessionID
session_start();$_SESSION['visits']++;print'You have visited here '.$_SESSION['visits'].' times.
';echo'session id = '.$_COOKIE['PHPSESSID'];echo"
";echo"session name = ".session_name()."
";?>
SessionID recorded in the global variable _cookie, SessionID's name is Phpsessid,phpsessid can also be obtained through Session_name ().
2 Prevention of Session hijacking
!--? php ini_set ( ' sessio.use_only_ Cookies ' , true ); Session_Start (); $salt = ' Yourspecialvaluehere ' ; $tokenstr = date ( ' W ' ). $salt ; $token = MD5 ( $tokenstr ); Echo ' token = ' . $token . '
' ; if (! isset ( $_request [ ' token ' ]) | | $_request [ token ' ]! = $token ) { exit ;} $_session [ ' token ' ] = $token ; Output_add_rewrite_var ( ' token ' , $token ); Echo ' link ' ; Ob_flush (); Output_reset_rewrite_vars (); ?
session_start();output_add_rewrite_var('var', 'value');echo'link';ob_flush();output_reset_rewrite_vars();echo'link';?>以上例程会输出:<ahref="file.php?PHPSESSID=xxx&var=value">link
a><ahref="file.php">link
a>
3 Prevention Session Customization
- The session identifier is not appended to the session cookie on the URL.
- Frequent generation of new SessionID
ini_set('session.use_only_cookie', true);session_start();if(!isset($_SESSION['generated']) || $_SESSION['generated'] < (time() - 30)){ session_regenerate_id(); $_SESSION['generated'] = time();}echo$_COOKIE['PHPSESSID']
'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
'). Text (i)); }; $numbering. FadeIn (1700); }); });
The above describes a session and data retention, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.