Working with Session Variables in PHP - Part 1
I can retrieve when I was learning to programme in PHP a few old age ago, people talking about things called session variables and thought that it all sounded a spot scary. What were these things that people kept saying were so useful, and what were they used for?
Whenever I looked anything up on the Internet to make with session variables, the gap statement was normally something about hypertext transfer communications protocol being a stateless protocol - so I was lost consecutive away. What was a stateless communications protocol when it was at home?
In this article I'm not going to utilize fancy technical footing to depict what session variables are and what they are used for, instead, I'm going to utilize apparent English...or at least attempt to!
Let's start at the beginning. If I establish my web browser and unfastened the place page of a web site, and then, from that page, chink on a nexus to open up another page on the same web site, the web waiter that sent the first page to my computing machine have no manner of knowing that it is me who have also asked for the 2nd page. The web waiter simply 'serves' pages as they are requested by a web browser - it doesn't maintain path of who is requesting them.
In many lawsuits this isn't a problem, because it doesn't substance that the web waiter doesn't cognize that it was me (or rather the web browser running on my computer) who requested both pages. However, if the web land land land land site necessitates me to log on in order to open up subsequent pages on the site, the web waiter makes demand to cognize that it is me who is requesting the 2nd page.
Session variables enable a web waiter to maintain path of a web site visitant as they voyage around the site. Otherwise, you would have got to log on to each page on the land site individually, which would be a spot of a retarding force to state the least.
Session variables are simply variables that last for the continuance of a session. This enables the web waiter to delegate my login name, for example, to a session variable called, say, 'username', and then to check up on the value inside that variable for all pages that necessitate me to be logged on in order to entree them.
What is a session? I can here you saying. A session is simply the clip from when you begin your web browser to when you close it. If you log on to a peculiar web site, and then voyage away from it to another site, you will (normally) still be logged onto the first land land land site until you close the web browser. OK, there are other ways that mightiness cause you to be logged off the first site, but in general, that's the manner it works.
In Part 2 we will put up a simple session and expression at how to utilize session variables.
Labels: php, session variable, variable, web development
0 Comments:
Post a Comment
<< Home