What is session? What are the ways to do session tracking? How session tracking is done in PHP

Mumbai University > Information Technology > Sem 4 > Web Programming

Marks: 10M

Year: May 2014, Dec 2014, May 2015 , Dec 2015

1 Answer
  • When a user logs in to a application, performs some activity and close the application, this entire scenario is called as session.
  • A web server needs to track all the activities of users. It needs to store required information about the user. This whole process is called as session tracking.
  • There exists a session array which often stores the unique session ID for the session.
  • PHP keep tracks of session by using a function called session_start().
  • When session_start() function is invoked , session ID is created and recorded.

Following is a PHP code:

    echo “You are visiting this page for:”$_SESSION [‘PGVISIT’])” times”;
echo “You are visiting this page for the first time”;
  • Another way to store information is using Cookies. Cookies is a small file that server embeds in a user’s machine.
  • Cookies are used to identify users. It consists of a name and textual value. It can be created by some software system on the server.
  • In every HTTP communication between browser and server, a header is included.
  • The header part contains the information stored in cookies, about the message. -- In PHP, a function setcookie() can be used to create cookie.

  • An information from the cookie can be retrieved in a following way:

         echo “Welcome” .$_COOKIE[“Myname”].”….!!”;?>
Please log in to add an answer.