Wednesday, 14 May 2014

what is Sessions

*    A PHP session variable is used to store information about, or change settings for a user session. Session variables hold information about one single user, and are available to all pages in one application.
*  In computer science, in particular networking, a session is a semi-permanent interactive information interchange, also known as a dialogue, a conversation or a meeting, between two or more communicating devices, or between a computer and user (see Login session). A session is set up or established at a certain point in time, and then torn down at some later point. An established communication session may involve more than one message in each direction. A session is typically, but not always, stateful, meaning that at least one of the communicating parts needs to save information about the session history in order to be able to communicate, as opposed to statelesscommunication, where the communication consists of independent requests with responses.

Communication sessions may be implemented as part of protocols and services at the application layer, at thesession layer or at the transport layer in the OSI model.
  • Application layer examples:
    • HTTP sessions, which allow associating information with individual visitors
    • telnet remote login session
  • Session layer example:
  • Transport layer example:
    • TCP session, which is synonymous to a TCP virtual circuit, a TCP connection, or an established TCPsocket.
    • Session management

    • In human–computer interactionsession management is the process of keeping track of a user's activity across sessions of interaction with the computer system.
      Typical session management tasks in a desktop environment include keeping track of which applications are open and which documents each application has opened, so that the same state can be restored when the user logs out and logs in later. For a website, session management might involve requiring the user to re-login if the session has expired (i.e., a certain time limit has passed without user activity). It is also used to store information on the server-side between HTTP requests.

      Desktop session management

      A desktop session manager is a program that can save and restore desktop sessions. A desktop session is all the windows currently running and their current content. Session management on Linux-based systems is provided by X session manager. On Microsoft Windows systems, no session manager is included in the system, but session management can be provided by third-party applications like twinsplay.

      Browser session management

      Session management is particularly useful in a web browser where a user can save all open pages and settings and restore them at a later date. To help recover from a system or application crash, pages and settings can also be restored on next run. Google ChromeMozilla FirefoxInternet ExplorerOmniWeb and Opera are examples of web browsers that support session management. Session management is often managed through the application ofcookies.
    • PHP Session VariablesWhen you are working with an application, you open it, do some changes and then you close it. This is much like a Session. The computer knows who you are. It knows when you start the application and when you end. But on the internet there is one problem: the web server does not know who you are and what you do because the HTTP address doesn't maintain state.

      A PHP session solves this problem by allowing you to store user information on the server for later use (i.e. username, shopping items, etc). However, session information is temporary and will be deleted after the user has left the website. If you need a permanent storage you may want to store the data in a database.
      Sessions work by creating a unique id (UID) for each visitor and store variables based on this UID. The UID is either stored in a cookie or is propagated in the URL.
    • <?php session_start(); ?>

      <html>
      <body>

      </body>
      </html>
    • Storing a Session Variable

      The correct way to store and retrieve session variables is to use the PHP $_SESSION variable:
      <?php
      session_start();
      // store session data
      $_SESSION['views']=1;
      ?>

      <html>
      <body>

      <?php
      //retrieve session data
      echo "Pageviews=". $_SESSION['views'];
      ?>

      </body></html>

No comments:

Post a Comment