How to use the session

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.