Concept: Session to the client data in the server, to the browser a cryptographic credentials, each login generated credentials are not the same, the browser with a cookie to save the voucher. The next time the server receives the voucher, open the file to read the session information. Session_Start (); Open session$_session[' user '] = ' Liudehua '; Add parameter echo$_session[' user ']; Read the directory address saved by the Sessionsession voucher, which has Session.save_path = "d:/php" in php.ini.
The session life cycle:
Session
The session object is placed on the server side, and the client puts a string of JSessionID32 bits!
Jsessionid is placed in the client's cookie!
Each time you use the session, you need the client's jsessionid to identify that session is the customer!
If the session remains Jsessionid,
1:jsessionid is placed in the client's cookie!
2: If the client does not support cookies, it will use URL rewriting technology! Http://localhost:8080/web/cookie2.jsp?JSESSIIONID=DAA7D525F404B5113006A519A003252D
When the session is destroyed:
1:session Timeout 30 minutes in a daze, the current session! will be destroyed.
2:session.invalidate (); the programmer destroys it manually!
Session Monitoring:
Listen for session creation and session destruction!
public class MyListener implements Httpsessionlistener {
public static int online = 0;
public void sessioncreated (Httpsessionevent arg0) {
TODO auto-generated Method Stub
System.out.println ("Create a Session");
online++;;
}
public void sessiondestroyed (Httpsessionevent arg0) {
TODO auto-generated Method Stub
System.out.println ("Destroying a Session");
online--;
}
}
The listener must be registered in the XML:
<listener>
<listener-class>com.edu.MyListener</listener-class>
</listener>
Excellent Yue Group (Shenzhen) Co., Ltd.
Enjoy Life with technology
: Yojoygroup
Weibo: Http://weibo.com/YOJOYGROUP
Official website:http://www.yojoygroup.com/
Contact & submission: [Email protected]
How to use the session