11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 18 • SESSION HANDLERSwww.it-ebooks.infoboolean session_destroy()If you are not interested in using the cookie beyond the end of the session, just setsession.cookie_lifetime to 0 (its default value) in the php.ini file.Setting and Retrieving the Session IDRemember that the SID ties all session data to a particular user. Although <strong>PHP</strong> will both create andpropagate the SID autonomously, there are times when you may wish to manually set or retrieve it. Thefunction session_id() is capable of carrying out both tasks. Its prototype looks like this:string session_id([string sid])The function session_id() can both set and get the SID. If it is passed no parameter, the functionsession_id() returns the current SID. If the optional SID parameter is included, the current SID will bereplaced with that value. An example follows:This results in output similar to the following:Your session identification number is 967d992a949114ee9832f1c11cIf you’d like to create a custom session handler, supported characters are limited to alphanumericcharacters, the comma, and the minus sign.Creating and Deleting Session VariablesSession variables are used to manage the data intended to travel with the user from one page to the next.These days, however, the preferred method involves simply setting and deleting these variable just likeany other, except that you need to refer to it in the context of the $_SESSION superglobal. For example,suppose you wanted to set a session variable named username:This returns the following:Your username is Jason.374

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!