sessions.html 122 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922
  1. <!DOCTYPE html>
  2. <!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
  3. <!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
  4. <head>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Session Library &mdash; CodeIgniter 3.1.11 documentation</title>
  8. <link rel="shortcut icon" href="../_static/ci-icon.ico"/>
  9. <link href='https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic|Roboto+Slab:400,700|Inconsolata:400,700&subset=latin,cyrillic' rel='stylesheet' type='text/css'>
  10. <link rel="stylesheet" href="../_static/css/citheme.css" type="text/css" />
  11. <link rel="index" title="Index"
  12. href="../genindex.html"/>
  13. <link rel="search" title="Search" href="../search.html"/>
  14. <link rel="top" title="CodeIgniter 3.1.11 documentation" href="../index.html"/>
  15. <link rel="up" title="Libraries" href="index.html"/>
  16. <link rel="next" title="HTML Table Class" href="table.html"/>
  17. <link rel="prev" title="Security Class" href="security.html"/>
  18. <script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
  19. </head>
  20. <body class="wy-body-for-nav" role="document">
  21. <div id="nav">
  22. <div id="nav_inner">
  23. <div id="pulldown-menu" class="ciNav">
  24. <ul>
  25. <li class="toctree-l1"><a class="reference internal" href="../general/welcome.html">Welcome to CodeIgniter</a></li>
  26. </ul>
  27. <ul>
  28. <li class="toctree-l1"><a class="reference internal" href="../installation/index.html">Installation Instructions</a><ul>
  29. <li class="toctree-l2"><a class="reference internal" href="../installation/downloads.html">Downloading CodeIgniter</a></li>
  30. <li class="toctree-l2"><a class="reference internal" href="../installation/index.html">Installation Instructions</a></li>
  31. <li class="toctree-l2"><a class="reference internal" href="../installation/upgrading.html">Upgrading From a Previous Version</a></li>
  32. <li class="toctree-l2"><a class="reference internal" href="../installation/troubleshooting.html">Troubleshooting</a></li>
  33. </ul>
  34. </li>
  35. </ul>
  36. <ul>
  37. <li class="toctree-l1"><a class="reference internal" href="../overview/index.html">CodeIgniter Overview</a><ul>
  38. <li class="toctree-l2"><a class="reference internal" href="../overview/getting_started.html">Getting Started</a></li>
  39. <li class="toctree-l2"><a class="reference internal" href="../overview/at_a_glance.html">CodeIgniter at a Glance</a></li>
  40. <li class="toctree-l2"><a class="reference internal" href="../overview/features.html">Supported Features</a></li>
  41. <li class="toctree-l2"><a class="reference internal" href="../overview/appflow.html">Application Flow Chart</a></li>
  42. <li class="toctree-l2"><a class="reference internal" href="../overview/mvc.html">Model-View-Controller</a></li>
  43. <li class="toctree-l2"><a class="reference internal" href="../overview/goals.html">Architectural Goals</a></li>
  44. </ul>
  45. </li>
  46. </ul>
  47. <ul>
  48. <li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">Tutorial</a><ul>
  49. <li class="toctree-l2"><a class="reference internal" href="../tutorial/static_pages.html">Static pages</a></li>
  50. <li class="toctree-l2"><a class="reference internal" href="../tutorial/news_section.html">News section</a></li>
  51. <li class="toctree-l2"><a class="reference internal" href="../tutorial/create_news_items.html">Create news items</a></li>
  52. <li class="toctree-l2"><a class="reference internal" href="../tutorial/conclusion.html">Conclusion</a></li>
  53. </ul>
  54. </li>
  55. </ul>
  56. <ul>
  57. <li class="toctree-l1"><a class="reference internal" href="../contributing/index.html">Contributing to CodeIgniter</a><ul>
  58. <li class="toctree-l2"><a class="reference internal" href="../documentation/index.html">Writing CodeIgniter Documentation</a></li>
  59. <li class="toctree-l2"><a class="reference internal" href="../DCO.html">Developer’s Certificate of Origin 1.1</a></li>
  60. </ul>
  61. </li>
  62. </ul>
  63. <ul>
  64. <li class="toctree-l1"><a class="reference internal" href="../general/index.html">General Topics</a><ul>
  65. <li class="toctree-l2"><a class="reference internal" href="../general/urls.html">CodeIgniter URLs</a></li>
  66. <li class="toctree-l2"><a class="reference internal" href="../general/controllers.html">Controllers</a></li>
  67. <li class="toctree-l2"><a class="reference internal" href="../general/reserved_names.html">Reserved Names</a></li>
  68. <li class="toctree-l2"><a class="reference internal" href="../general/views.html">Views</a></li>
  69. <li class="toctree-l2"><a class="reference internal" href="../general/models.html">Models</a></li>
  70. <li class="toctree-l2"><a class="reference internal" href="../general/helpers.html">Helpers</a></li>
  71. <li class="toctree-l2"><a class="reference internal" href="../general/libraries.html">Using CodeIgniter Libraries</a></li>
  72. <li class="toctree-l2"><a class="reference internal" href="../general/creating_libraries.html">Creating Libraries</a></li>
  73. <li class="toctree-l2"><a class="reference internal" href="../general/drivers.html">Using CodeIgniter Drivers</a></li>
  74. <li class="toctree-l2"><a class="reference internal" href="../general/creating_drivers.html">Creating Drivers</a></li>
  75. <li class="toctree-l2"><a class="reference internal" href="../general/core_classes.html">Creating Core System Classes</a></li>
  76. <li class="toctree-l2"><a class="reference internal" href="../general/ancillary_classes.html">Creating Ancillary Classes</a></li>
  77. <li class="toctree-l2"><a class="reference internal" href="../general/hooks.html">Hooks - Extending the Framework Core</a></li>
  78. <li class="toctree-l2"><a class="reference internal" href="../general/autoloader.html">Auto-loading Resources</a></li>
  79. <li class="toctree-l2"><a class="reference internal" href="../general/common_functions.html">Common Functions</a></li>
  80. <li class="toctree-l2"><a class="reference internal" href="../general/compatibility_functions.html">Compatibility Functions</a></li>
  81. <li class="toctree-l2"><a class="reference internal" href="../general/routing.html">URI Routing</a></li>
  82. <li class="toctree-l2"><a class="reference internal" href="../general/errors.html">Error Handling</a></li>
  83. <li class="toctree-l2"><a class="reference internal" href="../general/caching.html">Caching</a></li>
  84. <li class="toctree-l2"><a class="reference internal" href="../general/profiling.html">Profiling Your Application</a></li>
  85. <li class="toctree-l2"><a class="reference internal" href="../general/cli.html">Running via the CLI</a></li>
  86. <li class="toctree-l2"><a class="reference internal" href="../general/managing_apps.html">Managing your Applications</a></li>
  87. <li class="toctree-l2"><a class="reference internal" href="../general/environments.html">Handling Multiple Environments</a></li>
  88. <li class="toctree-l2"><a class="reference internal" href="../general/alternative_php.html">Alternate PHP Syntax for View Files</a></li>
  89. <li class="toctree-l2"><a class="reference internal" href="../general/security.html">Security</a></li>
  90. <li class="toctree-l2"><a class="reference internal" href="../general/styleguide.html">PHP Style Guide</a></li>
  91. </ul>
  92. </li>
  93. </ul>
  94. <ul class="current">
  95. <li class="toctree-l1 current"><a class="reference internal" href="index.html">Libraries</a><ul class="current">
  96. <li class="toctree-l2"><a class="reference internal" href="benchmark.html">Benchmarking Class</a></li>
  97. <li class="toctree-l2"><a class="reference internal" href="caching.html">Caching Driver</a></li>
  98. <li class="toctree-l2"><a class="reference internal" href="calendar.html">Calendaring Class</a></li>
  99. <li class="toctree-l2"><a class="reference internal" href="cart.html">Shopping Cart Class</a></li>
  100. <li class="toctree-l2"><a class="reference internal" href="config.html">Config Class</a></li>
  101. <li class="toctree-l2"><a class="reference internal" href="email.html">Email Class</a></li>
  102. <li class="toctree-l2"><a class="reference internal" href="encrypt.html">Encrypt Class</a></li>
  103. <li class="toctree-l2"><a class="reference internal" href="encryption.html">Encryption Library</a></li>
  104. <li class="toctree-l2"><a class="reference internal" href="file_uploading.html">File Uploading Class</a></li>
  105. <li class="toctree-l2"><a class="reference internal" href="form_validation.html">Form Validation</a></li>
  106. <li class="toctree-l2"><a class="reference internal" href="ftp.html">FTP Class</a></li>
  107. <li class="toctree-l2"><a class="reference internal" href="image_lib.html">Image Manipulation Class</a></li>
  108. <li class="toctree-l2"><a class="reference internal" href="input.html">Input Class</a></li>
  109. <li class="toctree-l2"><a class="reference internal" href="javascript.html">Javascript Class</a></li>
  110. <li class="toctree-l2"><a class="reference internal" href="language.html">Language Class</a></li>
  111. <li class="toctree-l2"><a class="reference internal" href="loader.html">Loader Class</a></li>
  112. <li class="toctree-l2"><a class="reference internal" href="migration.html">Migrations Class</a></li>
  113. <li class="toctree-l2"><a class="reference internal" href="output.html">Output Class</a></li>
  114. <li class="toctree-l2"><a class="reference internal" href="pagination.html">Pagination Class</a></li>
  115. <li class="toctree-l2"><a class="reference internal" href="parser.html">Template Parser Class</a></li>
  116. <li class="toctree-l2"><a class="reference internal" href="security.html">Security Class</a></li>
  117. <li class="toctree-l2 current"><a class="current reference internal" href="#">Session Library</a></li>
  118. <li class="toctree-l2"><a class="reference internal" href="table.html">HTML Table Class</a></li>
  119. <li class="toctree-l2"><a class="reference internal" href="trackback.html">Trackback Class</a></li>
  120. <li class="toctree-l2"><a class="reference internal" href="typography.html">Typography Class</a></li>
  121. <li class="toctree-l2"><a class="reference internal" href="unit_testing.html">Unit Testing Class</a></li>
  122. <li class="toctree-l2"><a class="reference internal" href="uri.html">URI Class</a></li>
  123. <li class="toctree-l2"><a class="reference internal" href="user_agent.html">User Agent Class</a></li>
  124. <li class="toctree-l2"><a class="reference internal" href="xmlrpc.html">XML-RPC and XML-RPC Server Classes</a></li>
  125. <li class="toctree-l2"><a class="reference internal" href="zip.html">Zip Encoding Class</a></li>
  126. </ul>
  127. </li>
  128. </ul>
  129. <ul>
  130. <li class="toctree-l1"><a class="reference internal" href="../database/index.html">Database Reference</a><ul>
  131. <li class="toctree-l2"><a class="reference internal" href="../database/examples.html">Quick Start: Usage Examples</a></li>
  132. <li class="toctree-l2"><a class="reference internal" href="../database/configuration.html">Database Configuration</a></li>
  133. <li class="toctree-l2"><a class="reference internal" href="../database/connecting.html">Connecting to a Database</a></li>
  134. <li class="toctree-l2"><a class="reference internal" href="../database/queries.html">Running Queries</a></li>
  135. <li class="toctree-l2"><a class="reference internal" href="../database/results.html">Generating Query Results</a></li>
  136. <li class="toctree-l2"><a class="reference internal" href="../database/helpers.html">Query Helper Functions</a></li>
  137. <li class="toctree-l2"><a class="reference internal" href="../database/query_builder.html">Query Builder Class</a></li>
  138. <li class="toctree-l2"><a class="reference internal" href="../database/transactions.html">Transactions</a></li>
  139. <li class="toctree-l2"><a class="reference internal" href="../database/metadata.html">Getting MetaData</a></li>
  140. <li class="toctree-l2"><a class="reference internal" href="../database/call_function.html">Custom Function Calls</a></li>
  141. <li class="toctree-l2"><a class="reference internal" href="../database/caching.html">Query Caching</a></li>
  142. <li class="toctree-l2"><a class="reference internal" href="../database/forge.html">Database Manipulation with Database Forge</a></li>
  143. <li class="toctree-l2"><a class="reference internal" href="../database/utilities.html">Database Utilities Class</a></li>
  144. <li class="toctree-l2"><a class="reference internal" href="../database/db_driver_reference.html">Database Driver Reference</a></li>
  145. </ul>
  146. </li>
  147. </ul>
  148. <ul>
  149. <li class="toctree-l1"><a class="reference internal" href="../helpers/index.html">Helpers</a><ul>
  150. <li class="toctree-l2"><a class="reference internal" href="../helpers/array_helper.html">Array Helper</a></li>
  151. <li class="toctree-l2"><a class="reference internal" href="../helpers/captcha_helper.html">CAPTCHA Helper</a></li>
  152. <li class="toctree-l2"><a class="reference internal" href="../helpers/cookie_helper.html">Cookie Helper</a></li>
  153. <li class="toctree-l2"><a class="reference internal" href="../helpers/date_helper.html">Date Helper</a></li>
  154. <li class="toctree-l2"><a class="reference internal" href="../helpers/directory_helper.html">Directory Helper</a></li>
  155. <li class="toctree-l2"><a class="reference internal" href="../helpers/download_helper.html">Download Helper</a></li>
  156. <li class="toctree-l2"><a class="reference internal" href="../helpers/email_helper.html">Email Helper</a></li>
  157. <li class="toctree-l2"><a class="reference internal" href="../helpers/file_helper.html">File Helper</a></li>
  158. <li class="toctree-l2"><a class="reference internal" href="../helpers/form_helper.html">Form Helper</a></li>
  159. <li class="toctree-l2"><a class="reference internal" href="../helpers/html_helper.html">HTML Helper</a></li>
  160. <li class="toctree-l2"><a class="reference internal" href="../helpers/inflector_helper.html">Inflector Helper</a></li>
  161. <li class="toctree-l2"><a class="reference internal" href="../helpers/language_helper.html">Language Helper</a></li>
  162. <li class="toctree-l2"><a class="reference internal" href="../helpers/number_helper.html">Number Helper</a></li>
  163. <li class="toctree-l2"><a class="reference internal" href="../helpers/path_helper.html">Path Helper</a></li>
  164. <li class="toctree-l2"><a class="reference internal" href="../helpers/security_helper.html">Security Helper</a></li>
  165. <li class="toctree-l2"><a class="reference internal" href="../helpers/smiley_helper.html">Smiley Helper</a></li>
  166. <li class="toctree-l2"><a class="reference internal" href="../helpers/string_helper.html">String Helper</a></li>
  167. <li class="toctree-l2"><a class="reference internal" href="../helpers/text_helper.html">Text Helper</a></li>
  168. <li class="toctree-l2"><a class="reference internal" href="../helpers/typography_helper.html">Typography Helper</a></li>
  169. <li class="toctree-l2"><a class="reference internal" href="../helpers/url_helper.html">URL Helper</a></li>
  170. <li class="toctree-l2"><a class="reference internal" href="../helpers/xml_helper.html">XML Helper</a></li>
  171. </ul>
  172. </li>
  173. </ul>
  174. </div>
  175. </div>
  176. </div>
  177. <div id="nav2">
  178. <a href="#" id="openToc">
  179. <img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAARgAA/+4ADkFkb2JlAGTAAAAAAf/bAIQABAMDAwMDBAMDBAYEAwQGBwUEBAUHCAYGBwYGCAoICQkJCQgKCgwMDAwMCgwMDQ0MDBERERERFBQUFBQUFBQUFAEEBQUIBwgPCgoPFA4ODhQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU/8AAEQgAKwCaAwERAAIRAQMRAf/EAHsAAQAABwEBAAAAAAAAAAAAAAABAwQFBgcIAgkBAQAAAAAAAAAAAAAAAAAAAAAQAAEDAwICBwYEAgsAAAAAAAIBAwQAEQUSBiEHkROTVNQWGDFBUVIUCHEiMtOUFWGBobHRQlMkZIRVEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwDSC+ygkOOaUoKigUCgUCgUCgUCgUCgUCgUCgkuGguIP9FBMFb0Hqg7We+3jlmIqqYFf4ub+/QYlnOR/LqIBKGFUbf8qWv971BytQXXE7Y3Lnm3HsFhp2TaZJAdchRXpIgSpdEJWxJEW3xoKV7F5OMy7JkQn2o7D6w33XGjEAkoiqrJEqIiOIiKuhePCgqp22dyYyS3CyWHnQ5joG61HkRnmnTbaFSMhExRVQRRVJU9iUHjE7ez+fJ0MFipmUNhBV8YUd2SoIV9KkjQla9ltegttBdPLW4/qocL+UTfrMiHW4+P9M71shuyrqaHTcxsl7jegpsji8nh5ZwMvDfgTm0RTjSmjYdFCS6KoOIipdFunCgmNYTMv457MMY6U7iI6oMieDDhRm1VbIhuoOkbqtuK0Hpzb+eZcYZexUxt6UyUqK2cd0SdjtgrhOgijcgERUlJOCIl6CpgbP3blRI8XgMjNARAyKNDfeRBdFDBVUAXgQrqH4pxoJTu2NysY97LP4ac1io5q1InHFeGO24LnVKJuKOkSQ/yKir+rh7aCLG1dzypZQI2FnvTgccYOM3FeN0XWERXAUEFVQgQkUktdLpegm+Td3/Xli/L+S/mYNJIOF9G/wBeLKrZHFb0akG6W1WtQWSg3Dyg5e7V3fipE3O4/wCrktyzYA+ufas2LbZIlmnAT2kvuoN1wft95augilglX/tzP3qCu9O3LL/wV/i5v79BvmTADq14UGu91467Z6U9y0HzH/ncj/U/sT/CgynZG7I2NezpZGUjIycJkYkZSG+uQ81pbBNKLxJfjwoMqZ3/ALYHl35AJ7/cuwHcu5k7r1Q5pHetBjquqVVJWGxj9Zrtcl/Ggy3dHMvauR3HFZj5nHNxSyW5JISYDMoIwx8tFIGHZhPNaykGapr6rUAiicEoMG21lMRj8buPAz8xhJrr7uOeiPTCyAwXUaGR1mgozbTusOsFLEiJ7fbQa/h7gcjy2H3V6xppwDNtUSxCJIqp7valBuWVzJ22xuCROXNNZiJkMtms0DbjUkAZjzoDrTMd9dDRI44ZC2YsrYdKWP2WDT2S3N9dNdlRYrGMYc06IURXSYb0igrpWS485xVNS6nF4rwslkoMwnbpgZLB7bmt5uMweAhDEl4B5uSLzzqTnnyVpW2jaJHRMSIjdDiiotvy3DOE5rYTEbkl5yFn28k7JyG4c7AU2HtLH1uKfaiMPI40CdYbpNtmLdwTSn5rewLNld+7TLdeal4WarWBkbVKBjgdElMJJwAAY5fl4kB3b1fp4XvagsGS3FjJfLzDNtS8aeXx7LzT7TyzByQE5PccRGRC0ZRUDRV6y62vbjagzLmJzS2vuPK43JY6aP1TW6Jz+RIWyFtyC06y3EkiiinAo7YCqfq1AqqnGgsOH3lhZO8d1pmcpB8j5XIm9OYlBJSQ/FSS4427DKO0RC8AlcEMhFdViRR1WDWR5t3WXVuL1d106kG9vdeye2g60+1FDyW0shIcXVpyroXt8I8dfd+NB1vioAdWnD3UF1+gD4UFc6CEKpagxXN43rwJLUHz7yX2c8zokt9uHlsPIhA4aRnnHJTLptIS6CNsY7iASpxUUMkReGpfbQW0vtN5pitvrsN28rwtBD0nc0+/Yft5XhaB6TuaXfsP28rwtA9J3NPv2H7eV4Wgek7mn37D9vK8LQPSdzT79h+3leFoHpO5pd+w/byvC0D0nc0u/Yft5XhaB6TuaXfsP28rwtA9J3NLv2H7eV4Wgek7ml37D9vK8LQPSdzS79h+3leFoHpO5p9+w/byvC0E9r7Reazy2HIYVPxkS/CUHVn26cosxyv2g7h89LYmZSXOenvLEQ1YaQ222RATcQCP8rSGqqA8S02W2pQ6FhMoAIlqCtsnwoCpdKClejI4i3Sgtb+GBxVuNBSFt1pV/RQefLjPyUDy4z8lA8uM/JQPLjPyUDy4z8lA8uM/JQPLjPyUDy4z8lA8uM/JQPLjPyUDy4z8lA8utJ/koJ7WCbBU/LQXOPAFq1koK8B0pag90CggtBBf6qB0UDooHRQOigdFA6KB0UDooHRQOigdFA6KB0UDooI0EaBQf//Z" title="Toggle Table of Contents" alt="Toggle Table of Contents" />
  180. </a>
  181. </div>
  182. <div class="wy-grid-for-nav">
  183. <nav data-toggle="wy-nav-shift" class="wy-nav-side">
  184. <div class="wy-side-nav-search">
  185. <a href="../index.html" class="fa fa-home"> CodeIgniter</a>
  186. <div role="search">
  187. <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
  188. <input type="text" name="q" placeholder="Search docs" />
  189. <input type="hidden" name="check_keywords" value="yes" />
  190. <input type="hidden" name="area" value="default" />
  191. </form>
  192. </div>
  193. </div>
  194. <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
  195. <ul>
  196. <li class="toctree-l1"><a class="reference internal" href="../general/welcome.html">Welcome to CodeIgniter</a></li>
  197. </ul>
  198. <ul>
  199. <li class="toctree-l1"><a class="reference internal" href="../installation/index.html">Installation Instructions</a><ul>
  200. <li class="toctree-l2"><a class="reference internal" href="../installation/downloads.html">Downloading CodeIgniter</a></li>
  201. <li class="toctree-l2"><a class="reference internal" href="../installation/index.html">Installation Instructions</a></li>
  202. <li class="toctree-l2"><a class="reference internal" href="../installation/upgrading.html">Upgrading From a Previous Version</a></li>
  203. <li class="toctree-l2"><a class="reference internal" href="../installation/troubleshooting.html">Troubleshooting</a></li>
  204. </ul>
  205. </li>
  206. </ul>
  207. <ul>
  208. <li class="toctree-l1"><a class="reference internal" href="../overview/index.html">CodeIgniter Overview</a><ul>
  209. <li class="toctree-l2"><a class="reference internal" href="../overview/getting_started.html">Getting Started</a></li>
  210. <li class="toctree-l2"><a class="reference internal" href="../overview/at_a_glance.html">CodeIgniter at a Glance</a></li>
  211. <li class="toctree-l2"><a class="reference internal" href="../overview/features.html">Supported Features</a></li>
  212. <li class="toctree-l2"><a class="reference internal" href="../overview/appflow.html">Application Flow Chart</a></li>
  213. <li class="toctree-l2"><a class="reference internal" href="../overview/mvc.html">Model-View-Controller</a></li>
  214. <li class="toctree-l2"><a class="reference internal" href="../overview/goals.html">Architectural Goals</a></li>
  215. </ul>
  216. </li>
  217. </ul>
  218. <ul>
  219. <li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">Tutorial</a><ul>
  220. <li class="toctree-l2"><a class="reference internal" href="../tutorial/static_pages.html">Static pages</a></li>
  221. <li class="toctree-l2"><a class="reference internal" href="../tutorial/news_section.html">News section</a></li>
  222. <li class="toctree-l2"><a class="reference internal" href="../tutorial/create_news_items.html">Create news items</a></li>
  223. <li class="toctree-l2"><a class="reference internal" href="../tutorial/conclusion.html">Conclusion</a></li>
  224. </ul>
  225. </li>
  226. </ul>
  227. <ul>
  228. <li class="toctree-l1"><a class="reference internal" href="../contributing/index.html">Contributing to CodeIgniter</a><ul>
  229. <li class="toctree-l2"><a class="reference internal" href="../documentation/index.html">Writing CodeIgniter Documentation</a></li>
  230. <li class="toctree-l2"><a class="reference internal" href="../DCO.html">Developer’s Certificate of Origin 1.1</a></li>
  231. </ul>
  232. </li>
  233. </ul>
  234. <ul>
  235. <li class="toctree-l1"><a class="reference internal" href="../general/index.html">General Topics</a><ul>
  236. <li class="toctree-l2"><a class="reference internal" href="../general/urls.html">CodeIgniter URLs</a></li>
  237. <li class="toctree-l2"><a class="reference internal" href="../general/controllers.html">Controllers</a></li>
  238. <li class="toctree-l2"><a class="reference internal" href="../general/reserved_names.html">Reserved Names</a></li>
  239. <li class="toctree-l2"><a class="reference internal" href="../general/views.html">Views</a></li>
  240. <li class="toctree-l2"><a class="reference internal" href="../general/models.html">Models</a></li>
  241. <li class="toctree-l2"><a class="reference internal" href="../general/helpers.html">Helpers</a></li>
  242. <li class="toctree-l2"><a class="reference internal" href="../general/libraries.html">Using CodeIgniter Libraries</a></li>
  243. <li class="toctree-l2"><a class="reference internal" href="../general/creating_libraries.html">Creating Libraries</a></li>
  244. <li class="toctree-l2"><a class="reference internal" href="../general/drivers.html">Using CodeIgniter Drivers</a></li>
  245. <li class="toctree-l2"><a class="reference internal" href="../general/creating_drivers.html">Creating Drivers</a></li>
  246. <li class="toctree-l2"><a class="reference internal" href="../general/core_classes.html">Creating Core System Classes</a></li>
  247. <li class="toctree-l2"><a class="reference internal" href="../general/ancillary_classes.html">Creating Ancillary Classes</a></li>
  248. <li class="toctree-l2"><a class="reference internal" href="../general/hooks.html">Hooks - Extending the Framework Core</a></li>
  249. <li class="toctree-l2"><a class="reference internal" href="../general/autoloader.html">Auto-loading Resources</a></li>
  250. <li class="toctree-l2"><a class="reference internal" href="../general/common_functions.html">Common Functions</a></li>
  251. <li class="toctree-l2"><a class="reference internal" href="../general/compatibility_functions.html">Compatibility Functions</a></li>
  252. <li class="toctree-l2"><a class="reference internal" href="../general/routing.html">URI Routing</a></li>
  253. <li class="toctree-l2"><a class="reference internal" href="../general/errors.html">Error Handling</a></li>
  254. <li class="toctree-l2"><a class="reference internal" href="../general/caching.html">Caching</a></li>
  255. <li class="toctree-l2"><a class="reference internal" href="../general/profiling.html">Profiling Your Application</a></li>
  256. <li class="toctree-l2"><a class="reference internal" href="../general/cli.html">Running via the CLI</a></li>
  257. <li class="toctree-l2"><a class="reference internal" href="../general/managing_apps.html">Managing your Applications</a></li>
  258. <li class="toctree-l2"><a class="reference internal" href="../general/environments.html">Handling Multiple Environments</a></li>
  259. <li class="toctree-l2"><a class="reference internal" href="../general/alternative_php.html">Alternate PHP Syntax for View Files</a></li>
  260. <li class="toctree-l2"><a class="reference internal" href="../general/security.html">Security</a></li>
  261. <li class="toctree-l2"><a class="reference internal" href="../general/styleguide.html">PHP Style Guide</a></li>
  262. </ul>
  263. </li>
  264. </ul>
  265. <ul class="current">
  266. <li class="toctree-l1 current"><a class="reference internal" href="index.html">Libraries</a><ul class="current">
  267. <li class="toctree-l2"><a class="reference internal" href="benchmark.html">Benchmarking Class</a></li>
  268. <li class="toctree-l2"><a class="reference internal" href="caching.html">Caching Driver</a></li>
  269. <li class="toctree-l2"><a class="reference internal" href="calendar.html">Calendaring Class</a></li>
  270. <li class="toctree-l2"><a class="reference internal" href="cart.html">Shopping Cart Class</a></li>
  271. <li class="toctree-l2"><a class="reference internal" href="config.html">Config Class</a></li>
  272. <li class="toctree-l2"><a class="reference internal" href="email.html">Email Class</a></li>
  273. <li class="toctree-l2"><a class="reference internal" href="encrypt.html">Encrypt Class</a></li>
  274. <li class="toctree-l2"><a class="reference internal" href="encryption.html">Encryption Library</a></li>
  275. <li class="toctree-l2"><a class="reference internal" href="file_uploading.html">File Uploading Class</a></li>
  276. <li class="toctree-l2"><a class="reference internal" href="form_validation.html">Form Validation</a></li>
  277. <li class="toctree-l2"><a class="reference internal" href="ftp.html">FTP Class</a></li>
  278. <li class="toctree-l2"><a class="reference internal" href="image_lib.html">Image Manipulation Class</a></li>
  279. <li class="toctree-l2"><a class="reference internal" href="input.html">Input Class</a></li>
  280. <li class="toctree-l2"><a class="reference internal" href="javascript.html">Javascript Class</a></li>
  281. <li class="toctree-l2"><a class="reference internal" href="language.html">Language Class</a></li>
  282. <li class="toctree-l2"><a class="reference internal" href="loader.html">Loader Class</a></li>
  283. <li class="toctree-l2"><a class="reference internal" href="migration.html">Migrations Class</a></li>
  284. <li class="toctree-l2"><a class="reference internal" href="output.html">Output Class</a></li>
  285. <li class="toctree-l2"><a class="reference internal" href="pagination.html">Pagination Class</a></li>
  286. <li class="toctree-l2"><a class="reference internal" href="parser.html">Template Parser Class</a></li>
  287. <li class="toctree-l2"><a class="reference internal" href="security.html">Security Class</a></li>
  288. <li class="toctree-l2 current"><a class="current reference internal" href="#">Session Library</a></li>
  289. <li class="toctree-l2"><a class="reference internal" href="table.html">HTML Table Class</a></li>
  290. <li class="toctree-l2"><a class="reference internal" href="trackback.html">Trackback Class</a></li>
  291. <li class="toctree-l2"><a class="reference internal" href="typography.html">Typography Class</a></li>
  292. <li class="toctree-l2"><a class="reference internal" href="unit_testing.html">Unit Testing Class</a></li>
  293. <li class="toctree-l2"><a class="reference internal" href="uri.html">URI Class</a></li>
  294. <li class="toctree-l2"><a class="reference internal" href="user_agent.html">User Agent Class</a></li>
  295. <li class="toctree-l2"><a class="reference internal" href="xmlrpc.html">XML-RPC and XML-RPC Server Classes</a></li>
  296. <li class="toctree-l2"><a class="reference internal" href="zip.html">Zip Encoding Class</a></li>
  297. </ul>
  298. </li>
  299. </ul>
  300. <ul>
  301. <li class="toctree-l1"><a class="reference internal" href="../database/index.html">Database Reference</a><ul>
  302. <li class="toctree-l2"><a class="reference internal" href="../database/examples.html">Quick Start: Usage Examples</a></li>
  303. <li class="toctree-l2"><a class="reference internal" href="../database/configuration.html">Database Configuration</a></li>
  304. <li class="toctree-l2"><a class="reference internal" href="../database/connecting.html">Connecting to a Database</a></li>
  305. <li class="toctree-l2"><a class="reference internal" href="../database/queries.html">Running Queries</a></li>
  306. <li class="toctree-l2"><a class="reference internal" href="../database/results.html">Generating Query Results</a></li>
  307. <li class="toctree-l2"><a class="reference internal" href="../database/helpers.html">Query Helper Functions</a></li>
  308. <li class="toctree-l2"><a class="reference internal" href="../database/query_builder.html">Query Builder Class</a></li>
  309. <li class="toctree-l2"><a class="reference internal" href="../database/transactions.html">Transactions</a></li>
  310. <li class="toctree-l2"><a class="reference internal" href="../database/metadata.html">Getting MetaData</a></li>
  311. <li class="toctree-l2"><a class="reference internal" href="../database/call_function.html">Custom Function Calls</a></li>
  312. <li class="toctree-l2"><a class="reference internal" href="../database/caching.html">Query Caching</a></li>
  313. <li class="toctree-l2"><a class="reference internal" href="../database/forge.html">Database Manipulation with Database Forge</a></li>
  314. <li class="toctree-l2"><a class="reference internal" href="../database/utilities.html">Database Utilities Class</a></li>
  315. <li class="toctree-l2"><a class="reference internal" href="../database/db_driver_reference.html">Database Driver Reference</a></li>
  316. </ul>
  317. </li>
  318. </ul>
  319. <ul>
  320. <li class="toctree-l1"><a class="reference internal" href="../helpers/index.html">Helpers</a><ul>
  321. <li class="toctree-l2"><a class="reference internal" href="../helpers/array_helper.html">Array Helper</a></li>
  322. <li class="toctree-l2"><a class="reference internal" href="../helpers/captcha_helper.html">CAPTCHA Helper</a></li>
  323. <li class="toctree-l2"><a class="reference internal" href="../helpers/cookie_helper.html">Cookie Helper</a></li>
  324. <li class="toctree-l2"><a class="reference internal" href="../helpers/date_helper.html">Date Helper</a></li>
  325. <li class="toctree-l2"><a class="reference internal" href="../helpers/directory_helper.html">Directory Helper</a></li>
  326. <li class="toctree-l2"><a class="reference internal" href="../helpers/download_helper.html">Download Helper</a></li>
  327. <li class="toctree-l2"><a class="reference internal" href="../helpers/email_helper.html">Email Helper</a></li>
  328. <li class="toctree-l2"><a class="reference internal" href="../helpers/file_helper.html">File Helper</a></li>
  329. <li class="toctree-l2"><a class="reference internal" href="../helpers/form_helper.html">Form Helper</a></li>
  330. <li class="toctree-l2"><a class="reference internal" href="../helpers/html_helper.html">HTML Helper</a></li>
  331. <li class="toctree-l2"><a class="reference internal" href="../helpers/inflector_helper.html">Inflector Helper</a></li>
  332. <li class="toctree-l2"><a class="reference internal" href="../helpers/language_helper.html">Language Helper</a></li>
  333. <li class="toctree-l2"><a class="reference internal" href="../helpers/number_helper.html">Number Helper</a></li>
  334. <li class="toctree-l2"><a class="reference internal" href="../helpers/path_helper.html">Path Helper</a></li>
  335. <li class="toctree-l2"><a class="reference internal" href="../helpers/security_helper.html">Security Helper</a></li>
  336. <li class="toctree-l2"><a class="reference internal" href="../helpers/smiley_helper.html">Smiley Helper</a></li>
  337. <li class="toctree-l2"><a class="reference internal" href="../helpers/string_helper.html">String Helper</a></li>
  338. <li class="toctree-l2"><a class="reference internal" href="../helpers/text_helper.html">Text Helper</a></li>
  339. <li class="toctree-l2"><a class="reference internal" href="../helpers/typography_helper.html">Typography Helper</a></li>
  340. <li class="toctree-l2"><a class="reference internal" href="../helpers/url_helper.html">URL Helper</a></li>
  341. <li class="toctree-l2"><a class="reference internal" href="../helpers/xml_helper.html">XML Helper</a></li>
  342. </ul>
  343. </li>
  344. </ul>
  345. </div>
  346. &nbsp;
  347. </nav>
  348. <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
  349. <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
  350. <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
  351. <a href="../index.html">CodeIgniter</a>
  352. </nav>
  353. <div class="wy-nav-content">
  354. <div class="rst-content">
  355. <div role="navigation" aria-label="breadcrumbs navigation">
  356. <ul class="wy-breadcrumbs">
  357. <li><a href="../index.html">Docs</a> &raquo;</li>
  358. <li><a href="index.html">Libraries</a> &raquo;</li>
  359. <li>Session Library</li>
  360. <li class="wy-breadcrumbs-aside">
  361. </li>
  362. <div style="float:right;margin-left:5px;" id="closeMe">
  363. <img title="Classic Layout" alt="classic layout" src="data:image/gif;base64,R0lGODlhFAAUAJEAAAAAADMzM////wAAACH5BAUUAAIALAAAAAAUABQAAAImlI+py+0PU5gRBRDM3DxbWoXis42X13USOLauUIqnlsaH/eY6UwAAOw==" />
  364. </div>
  365. </ul>
  366. <hr/>
  367. </div>
  368. <div role="main" class="document">
  369. <div class="section" id="session-library">
  370. <h1>Session Library<a class="headerlink" href="#session-library" title="Permalink to this headline">¶</a></h1>
  371. <p>The Session class permits you maintain a user’s “state” and track their
  372. activity while they browse your site.</p>
  373. <p>CodeIgniter comes with a few session storage drivers:</p>
  374. <blockquote>
  375. <div><ul class="simple">
  376. <li>files (default; file-system based)</li>
  377. <li>database</li>
  378. <li>redis</li>
  379. <li>memcached</li>
  380. </ul>
  381. </div></blockquote>
  382. <p>In addition, you may create your own, custom session drivers based on other
  383. kinds of storage, while still taking advantage of the features of the
  384. Session class.</p>
  385. <div class="contents local topic" id="contents">
  386. <ul class="simple">
  387. <li><a class="reference internal" href="#using-the-session-class" id="id3">Using the Session Class</a><ul>
  388. <li><a class="reference internal" href="#initializing-a-session" id="id4">Initializing a Session</a></li>
  389. <li><a class="reference internal" href="#how-do-sessions-work" id="id5">How do Sessions work?</a><ul>
  390. <li><a class="reference internal" href="#a-note-about-concurrency" id="id6">A note about concurrency</a></li>
  391. </ul>
  392. </li>
  393. <li><a class="reference internal" href="#what-is-session-data" id="id7">What is Session Data?</a></li>
  394. <li><a class="reference internal" href="#retrieving-session-data" id="id8">Retrieving Session Data</a></li>
  395. <li><a class="reference internal" href="#adding-session-data" id="id9">Adding Session Data</a></li>
  396. <li><a class="reference internal" href="#removing-session-data" id="id10">Removing Session Data</a></li>
  397. <li><a class="reference internal" href="#flashdata" id="id11">Flashdata</a></li>
  398. <li><a class="reference internal" href="#tempdata" id="id12">Tempdata</a></li>
  399. <li><a class="reference internal" href="#destroying-a-session" id="id13">Destroying a Session</a></li>
  400. <li><a class="reference internal" href="#accessing-session-metadata" id="id14">Accessing session metadata</a></li>
  401. <li><a class="reference internal" href="#session-preferences" id="id15">Session Preferences</a></li>
  402. <li><a class="reference internal" href="#session-drivers" id="id16">Session Drivers</a><ul>
  403. <li><a class="reference internal" href="#files-driver" id="id17">Files Driver</a><ul>
  404. <li><a class="reference internal" href="#bonus-tip" id="id18">Bonus Tip</a></li>
  405. </ul>
  406. </li>
  407. <li><a class="reference internal" href="#database-driver" id="id19">Database Driver</a></li>
  408. <li><a class="reference internal" href="#redis-driver" id="id20">Redis Driver</a></li>
  409. <li><a class="reference internal" href="#memcached-driver" id="id21">Memcached Driver</a><ul>
  410. <li><a class="reference internal" href="#id1" id="id22">Bonus Tip</a></li>
  411. </ul>
  412. </li>
  413. <li><a class="reference internal" href="#custom-drivers" id="id23">Custom Drivers</a></li>
  414. </ul>
  415. </li>
  416. </ul>
  417. </li>
  418. <li><a class="reference internal" href="#class-reference" id="id24">Class Reference</a></li>
  419. </ul>
  420. </div>
  421. <div class="custom-index container"></div><div class="section" id="using-the-session-class">
  422. <h2><a class="toc-backref" href="#id3">Using the Session Class</a><a class="headerlink" href="#using-the-session-class" title="Permalink to this headline">¶</a></h2>
  423. <div class="section" id="initializing-a-session">
  424. <h3><a class="toc-backref" href="#id4">Initializing a Session</a><a class="headerlink" href="#initializing-a-session" title="Permalink to this headline">¶</a></h3>
  425. <p>Sessions will typically run globally with each page load, so the Session
  426. class should either be initialized in your <a class="reference internal" href="../general/controllers.html"><span class="doc">controller</span></a> constructors, or it can be <a class="reference internal" href="../general/autoloader.html"><span class="doc">auto-loaded</span></a> by the system.
  427. For the most part the session class will run unattended in the background,
  428. so simply initializing the class will cause it to read, create, and update
  429. sessions when necessary.</p>
  430. <p>To initialize the Session class manually in your controller constructor,
  431. use the <code class="docutils literal"><span class="pre">$this-&gt;load-&gt;library()</span></code> method:</p>
  432. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">load</span><span class="o">-&gt;</span><span class="na">library</span><span class="p">(</span><span class="s1">&#39;session&#39;</span><span class="p">);</span>
  433. </pre></div>
  434. </div>
  435. <p>Once loaded, the Sessions library object will be available using:</p>
  436. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span>
  437. </pre></div>
  438. </div>
  439. <div class="admonition important">
  440. <p class="first admonition-title">Important</p>
  441. <p class="last">Because the <a class="reference internal" href="loader.html"><span class="doc">Loader Class</span></a> is instantiated
  442. by CodeIgniter’s base controller, make sure to call
  443. <code class="docutils literal"><span class="pre">parent::__construct()</span></code> before trying to load a library from
  444. inside a controller constructor.</p>
  445. </div>
  446. </div>
  447. <div class="section" id="how-do-sessions-work">
  448. <h3><a class="toc-backref" href="#id5">How do Sessions work?</a><a class="headerlink" href="#how-do-sessions-work" title="Permalink to this headline">¶</a></h3>
  449. <p>When a page is loaded, the session class will check to see if valid
  450. session cookie is sent by the user’s browser. If a sessions cookie does
  451. <strong>not</strong> exist (or if it doesn’t match one stored on the server or has
  452. expired) a new session will be created and saved.</p>
  453. <p>If a valid session does exist, its information will be updated. With each
  454. update, the session ID may be regenerated if configured to do so.</p>
  455. <p>It’s important for you to understand that once initialized, the Session
  456. class runs automatically. There is nothing you need to do to cause the
  457. above behavior to happen. You can, as you’ll see below, work with session
  458. data, but the process of reading, writing, and updating a session is
  459. automatic.</p>
  460. <div class="admonition note">
  461. <p class="first admonition-title">Note</p>
  462. <p class="last">Under CLI, the Session library will automatically halt itself,
  463. as this is a concept based entirely on the HTTP protocol.</p>
  464. </div>
  465. <div class="section" id="a-note-about-concurrency">
  466. <h4><a class="toc-backref" href="#id6">A note about concurrency</a><a class="headerlink" href="#a-note-about-concurrency" title="Permalink to this headline">¶</a></h4>
  467. <p>Unless you’re developing a website with heavy AJAX usage, you can skip this
  468. section. If you are, however, and if you’re experiencing performance
  469. issues, then this note is exactly what you’re looking for.</p>
  470. <p>Sessions in previous versions of CodeIgniter didn’t implement locking,
  471. which meant that two HTTP requests using the same session could run exactly
  472. at the same time. To use a more appropriate technical term - requests were
  473. non-blocking.</p>
  474. <p>However, non-blocking requests in the context of sessions also means
  475. unsafe, because modifications to session data (or session ID regeneration)
  476. in one request can interfere with the execution of a second, concurrent
  477. request. This detail was at the root of many issues and the main reason why
  478. CodeIgniter 3.0 has a completely re-written Session library.</p>
  479. <p>Why are we telling you this? Because it is likely that after trying to
  480. find the reason for your performance issues, you may conclude that locking
  481. is the issue and therefore look into how to remove the locks …</p>
  482. <p>DO NOT DO THAT! Removing locks would be <strong>wrong</strong> and it will cause you
  483. more problems!</p>
  484. <p>Locking is not the issue, it is a solution. Your issue is that you still
  485. have the session open, while you’ve already processed it and therefore no
  486. longer need it. So, what you need is to close the session for the
  487. current request after you no longer need it.</p>
  488. <p>Long story short - call <code class="docutils literal"><span class="pre">session_write_close()</span></code> once you no longer need
  489. anything to do with session variables.</p>
  490. </div>
  491. </div>
  492. <div class="section" id="what-is-session-data">
  493. <h3><a class="toc-backref" href="#id7">What is Session Data?</a><a class="headerlink" href="#what-is-session-data" title="Permalink to this headline">¶</a></h3>
  494. <p>Session data is simply an array associated with a particular session ID
  495. (cookie).</p>
  496. <p>If you’ve used sessions in PHP before, you should be familiar with PHP’s
  497. <a class="reference external" href="http://php.net/manual/en/reserved.variables.session.php">$_SESSION superglobal</a>
  498. (if not, please read the content on that link).</p>
  499. <p>CodeIgniter gives access to its session data through the same means, as it
  500. uses the session handlers’ mechanism provided by PHP. Using session data is
  501. as simple as manipulating (read, set and unset values) the <code class="docutils literal"><span class="pre">$_SESSION</span></code>
  502. array.</p>
  503. <p>In addition, CodeIgniter also provides 2 special types of session data
  504. that are further explained below: flashdata and tempdata.</p>
  505. <div class="admonition note">
  506. <p class="first admonition-title">Note</p>
  507. <p class="last">In previous versions, regular session data in CodeIgniter was
  508. referred to as ‘userdata’. Have this in mind if that term is used
  509. elsewhere in the manual. Most of it is written to explain how
  510. the custom ‘userdata’ methods work.</p>
  511. </div>
  512. </div>
  513. <div class="section" id="retrieving-session-data">
  514. <h3><a class="toc-backref" href="#id8">Retrieving Session Data</a><a class="headerlink" href="#retrieving-session-data" title="Permalink to this headline">¶</a></h3>
  515. <p>Any piece of information from the session array is available through the
  516. <code class="docutils literal"><span class="pre">$_SESSION</span></code> superglobal:</p>
  517. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">&#39;item&#39;</span><span class="p">]</span>
  518. </pre></div>
  519. </div>
  520. <p>Or through the magic getter:</p>
  521. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">item</span>
  522. </pre></div>
  523. </div>
  524. <p>And for backwards compatibility, through the <code class="docutils literal"><span class="pre">userdata()</span></code> method:</p>
  525. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">userdata</span><span class="p">(</span><span class="s1">&#39;item&#39;</span><span class="p">);</span>
  526. </pre></div>
  527. </div>
  528. <p>Where item is the array key corresponding to the item you wish to fetch.
  529. For example, to assign a previously stored ‘name’ item to the <code class="docutils literal"><span class="pre">$name</span></code>
  530. variable, you will do this:</p>
  531. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$name</span> <span class="o">=</span> <span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">&#39;name&#39;</span><span class="p">];</span>
  532. <span class="c1">// or:</span>
  533. <span class="nv">$name</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">name</span>
  534. <span class="c1">// or:</span>
  535. <span class="nv">$name</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">userdata</span><span class="p">(</span><span class="s1">&#39;name&#39;</span><span class="p">);</span>
  536. </pre></div>
  537. </div>
  538. <div class="admonition note">
  539. <p class="first admonition-title">Note</p>
  540. <p class="last">The <code class="docutils literal"><span class="pre">userdata()</span></code> method returns NULL if the item you are trying
  541. to access does not exist.</p>
  542. </div>
  543. <p>If you want to retrieve all of the existing userdata, you can simply
  544. omit the item key (magic getter only works for properties):</p>
  545. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$_SESSION</span>
  546. <span class="c1">// or:</span>
  547. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">userdata</span><span class="p">();</span>
  548. </pre></div>
  549. </div>
  550. </div>
  551. <div class="section" id="adding-session-data">
  552. <h3><a class="toc-backref" href="#id9">Adding Session Data</a><a class="headerlink" href="#adding-session-data" title="Permalink to this headline">¶</a></h3>
  553. <p>Let’s say a particular user logs into your site. Once authenticated, you
  554. could add their username and e-mail address to the session, making that
  555. data globally available to you without having to run a database query when
  556. you need it.</p>
  557. <p>You can simply assign data to the <code class="docutils literal"><span class="pre">$_SESSION</span></code> array, as with any other
  558. variable. Or as a property of <code class="docutils literal"><span class="pre">$this-&gt;session</span></code>.</p>
  559. <p>Alternatively, the old method of assigning it as “userdata” is also
  560. available. That however passing an array containing your new data to the
  561. <code class="docutils literal"><span class="pre">set_userdata()</span></code> method:</p>
  562. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">set_userdata</span><span class="p">(</span><span class="nv">$array</span><span class="p">);</span>
  563. </pre></div>
  564. </div>
  565. <p>Where <code class="docutils literal"><span class="pre">$array</span></code> is an associative array containing your new data. Here’s
  566. an example:</p>
  567. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$newdata</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span>
  568. <span class="s1">&#39;username&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;johndoe&#39;</span><span class="p">,</span>
  569. <span class="s1">&#39;email&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;johndoe@some-site.com&#39;</span><span class="p">,</span>
  570. <span class="s1">&#39;logged_in&#39;</span> <span class="o">=&gt;</span> <span class="k">TRUE</span>
  571. <span class="p">);</span>
  572. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">set_userdata</span><span class="p">(</span><span class="nv">$newdata</span><span class="p">);</span>
  573. </pre></div>
  574. </div>
  575. <p>If you want to add userdata one value at a time, <code class="docutils literal"><span class="pre">set_userdata()</span></code> also
  576. supports this syntax:</p>
  577. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">set_userdata</span><span class="p">(</span><span class="s1">&#39;some_name&#39;</span><span class="p">,</span> <span class="s1">&#39;some_value&#39;</span><span class="p">);</span>
  578. </pre></div>
  579. </div>
  580. <p>If you want to verify that a session value exists, simply check with
  581. <code class="docutils literal"><span class="pre">isset()</span></code>:</p>
  582. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="c1">// returns FALSE if the &#39;some_name&#39; item doesn&#39;t exist or is NULL,</span>
  583. <span class="c1">// TRUE otherwise:</span>
  584. <span class="nb">isset</span><span class="p">(</span><span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">&#39;some_name&#39;</span><span class="p">])</span>
  585. </pre></div>
  586. </div>
  587. <p>Or you can call <code class="docutils literal"><span class="pre">has_userdata()</span></code>:</p>
  588. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">has_userdata</span><span class="p">(</span><span class="s1">&#39;some_name&#39;</span><span class="p">);</span>
  589. </pre></div>
  590. </div>
  591. </div>
  592. <div class="section" id="removing-session-data">
  593. <h3><a class="toc-backref" href="#id10">Removing Session Data</a><a class="headerlink" href="#removing-session-data" title="Permalink to this headline">¶</a></h3>
  594. <p>Just as with any other variable, unsetting a value in <code class="docutils literal"><span class="pre">$_SESSION</span></code> can be
  595. done through <code class="docutils literal"><span class="pre">unset()</span></code>:</p>
  596. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nb">unset</span><span class="p">(</span><span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">&#39;some_name&#39;</span><span class="p">]);</span>
  597. <span class="c1">// or multiple values:</span>
  598. <span class="nb">unset</span><span class="p">(</span>
  599. <span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">&#39;some_name&#39;</span><span class="p">],</span>
  600. <span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">&#39;another_name&#39;</span><span class="p">]</span>
  601. <span class="p">);</span>
  602. </pre></div>
  603. </div>
  604. <p>Also, just as <code class="docutils literal"><span class="pre">set_userdata()</span></code> can be used to add information to a
  605. session, <code class="docutils literal"><span class="pre">unset_userdata()</span></code> can be used to remove it, by passing the
  606. session key. For example, if you wanted to remove ‘some_name’ from your
  607. session data array:</p>
  608. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">unset_userdata</span><span class="p">(</span><span class="s1">&#39;some_name&#39;</span><span class="p">);</span>
  609. </pre></div>
  610. </div>
  611. <p>This method also accepts an array of item keys to unset:</p>
  612. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$array_items</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;username&#39;</span><span class="p">,</span> <span class="s1">&#39;email&#39;</span><span class="p">);</span>
  613. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">unset_userdata</span><span class="p">(</span><span class="nv">$array_items</span><span class="p">);</span>
  614. </pre></div>
  615. </div>
  616. <div class="admonition note">
  617. <p class="first admonition-title">Note</p>
  618. <p class="last">In previous versions, the <code class="docutils literal"><span class="pre">unset_userdata()</span></code> method used
  619. to accept an associative array of <code class="docutils literal"><span class="pre">key</span> <span class="pre">=&gt;</span> <span class="pre">'dummy</span> <span class="pre">value'</span></code>
  620. pairs. This is no longer supported.</p>
  621. </div>
  622. </div>
  623. <div class="section" id="flashdata">
  624. <h3><a class="toc-backref" href="#id11">Flashdata</a><a class="headerlink" href="#flashdata" title="Permalink to this headline">¶</a></h3>
  625. <p>CodeIgniter supports “flashdata”, or session data that will only be
  626. available for the next request, and is then automatically cleared.</p>
  627. <p>This can be very useful, especially for one-time informational, error or
  628. status messages (for example: “Record 2 deleted”).</p>
  629. <p>It should be noted that flashdata variables are regular session vars,
  630. only marked in a specific way under the ‘__ci_vars’ key (please don’t touch
  631. that one, you’ve been warned).</p>
  632. <p>To mark an existing item as “flashdata”:</p>
  633. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">mark_as_flash</span><span class="p">(</span><span class="s1">&#39;item&#39;</span><span class="p">);</span>
  634. </pre></div>
  635. </div>
  636. <p>If you want to mark multiple items as flashdata, simply pass the keys as an
  637. array:</p>
  638. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">mark_as_flash</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="s1">&#39;item&#39;</span><span class="p">,</span> <span class="s1">&#39;item2&#39;</span><span class="p">));</span>
  639. </pre></div>
  640. </div>
  641. <p>To add flashdata:</p>
  642. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">&#39;item&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;value&#39;</span><span class="p">;</span>
  643. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">mark_as_flash</span><span class="p">(</span><span class="s1">&#39;item&#39;</span><span class="p">);</span>
  644. </pre></div>
  645. </div>
  646. <p>Or alternatively, using the <code class="docutils literal"><span class="pre">set_flashdata()</span></code> method:</p>
  647. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">set_flashdata</span><span class="p">(</span><span class="s1">&#39;item&#39;</span><span class="p">,</span> <span class="s1">&#39;value&#39;</span><span class="p">);</span>
  648. </pre></div>
  649. </div>
  650. <p>You can also pass an array to <code class="docutils literal"><span class="pre">set_flashdata()</span></code>, in the same manner as
  651. <code class="docutils literal"><span class="pre">set_userdata()</span></code>.</p>
  652. <p>Reading flashdata variables is the same as reading regular session data
  653. through <code class="docutils literal"><span class="pre">$_SESSION</span></code>:</p>
  654. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">&#39;item&#39;</span><span class="p">]</span>
  655. </pre></div>
  656. </div>
  657. <div class="admonition important">
  658. <p class="first admonition-title">Important</p>
  659. <p class="last">The <code class="docutils literal"><span class="pre">userdata()</span></code> method will NOT return flashdata items.</p>
  660. </div>
  661. <p>However, if you want to be sure that you’re reading “flashdata” (and not
  662. any other kind), you can also use the <code class="docutils literal"><span class="pre">flashdata()</span></code> method:</p>
  663. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">flashdata</span><span class="p">(</span><span class="s1">&#39;item&#39;</span><span class="p">);</span>
  664. </pre></div>
  665. </div>
  666. <p>Or to get an array with all flashdata, simply omit the key parameter:</p>
  667. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">flashdata</span><span class="p">();</span>
  668. </pre></div>
  669. </div>
  670. <div class="admonition note">
  671. <p class="first admonition-title">Note</p>
  672. <p class="last">The <code class="docutils literal"><span class="pre">flashdata()</span></code> method returns NULL if the item cannot be
  673. found.</p>
  674. </div>
  675. <p>If you find that you need to preserve a flashdata variable through an
  676. additional request, you can do so using the <code class="docutils literal"><span class="pre">keep_flashdata()</span></code> method.
  677. You can either pass a single item or an array of flashdata items to keep.</p>
  678. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">keep_flashdata</span><span class="p">(</span><span class="s1">&#39;item&#39;</span><span class="p">);</span>
  679. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">keep_flashdata</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="s1">&#39;item1&#39;</span><span class="p">,</span> <span class="s1">&#39;item2&#39;</span><span class="p">,</span> <span class="s1">&#39;item3&#39;</span><span class="p">));</span>
  680. </pre></div>
  681. </div>
  682. </div>
  683. <div class="section" id="tempdata">
  684. <h3><a class="toc-backref" href="#id12">Tempdata</a><a class="headerlink" href="#tempdata" title="Permalink to this headline">¶</a></h3>
  685. <p>CodeIgniter also supports “tempdata”, or session data with a specific
  686. expiration time. After the value expires, or the session expires or is
  687. deleted, the value is automatically removed.</p>
  688. <p>Similarly to flashdata, tempdata variables are regular session vars that
  689. are marked in a specific way under the ‘__ci_vars’ key (again, don’t touch
  690. that one).</p>
  691. <p>To mark an existing item as “tempdata”, simply pass its key and expiry time
  692. (in seconds!) to the <code class="docutils literal"><span class="pre">mark_as_temp()</span></code> method:</p>
  693. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="c1">// &#39;item&#39; will be erased after 300 seconds</span>
  694. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">mark_as_temp</span><span class="p">(</span><span class="s1">&#39;item&#39;</span><span class="p">,</span> <span class="mi">300</span><span class="p">);</span>
  695. </pre></div>
  696. </div>
  697. <p>You can mark multiple items as tempdata in two ways, depending on whether
  698. you want them all to have the same expiry time or not:</p>
  699. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="c1">// Both &#39;item&#39; and &#39;item2&#39; will expire after 300 seconds</span>
  700. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">mark_as_temp</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="s1">&#39;item&#39;</span><span class="p">,</span> <span class="s1">&#39;item2&#39;</span><span class="p">),</span> <span class="mi">300</span><span class="p">);</span>
  701. <span class="c1">// &#39;item&#39; will be erased after 300 seconds, while &#39;item2&#39;</span>
  702. <span class="c1">// will do so after only 240 seconds</span>
  703. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">mark_as_temp</span><span class="p">(</span><span class="k">array</span><span class="p">(</span>
  704. <span class="s1">&#39;item&#39;</span> <span class="o">=&gt;</span> <span class="mi">300</span><span class="p">,</span>
  705. <span class="s1">&#39;item2&#39;</span> <span class="o">=&gt;</span> <span class="mi">240</span>
  706. <span class="p">));</span>
  707. </pre></div>
  708. </div>
  709. <p>To add tempdata:</p>
  710. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">&#39;item&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;value&#39;</span><span class="p">;</span>
  711. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">mark_as_temp</span><span class="p">(</span><span class="s1">&#39;item&#39;</span><span class="p">,</span> <span class="mi">300</span><span class="p">);</span> <span class="c1">// Expire in 5 minutes</span>
  712. </pre></div>
  713. </div>
  714. <p>Or alternatively, using the <code class="docutils literal"><span class="pre">set_tempdata()</span></code> method:</p>
  715. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">set_tempdata</span><span class="p">(</span><span class="s1">&#39;item&#39;</span><span class="p">,</span> <span class="s1">&#39;value&#39;</span><span class="p">,</span> <span class="mi">300</span><span class="p">);</span>
  716. </pre></div>
  717. </div>
  718. <p>You can also pass an array to <code class="docutils literal"><span class="pre">set_tempdata()</span></code>:</p>
  719. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$tempdata</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;newuser&#39;</span> <span class="o">=&gt;</span> <span class="k">TRUE</span><span class="p">,</span> <span class="s1">&#39;message&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;Thanks for joining!&#39;</span><span class="p">);</span>
  720. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">set_tempdata</span><span class="p">(</span><span class="nv">$tempdata</span><span class="p">,</span> <span class="k">NULL</span><span class="p">,</span> <span class="nv">$expire</span><span class="p">);</span>
  721. </pre></div>
  722. </div>
  723. <div class="admonition note">
  724. <p class="first admonition-title">Note</p>
  725. <p class="last">If the expiration is omitted or set to 0, the default
  726. time-to-live value of 300 seconds (or 5 minutes) will be used.</p>
  727. </div>
  728. <p>To read a tempdata variable, again you can just access it through the
  729. <code class="docutils literal"><span class="pre">$_SESSION</span></code> superglobal array:</p>
  730. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">&#39;item&#39;</span><span class="p">]</span>
  731. </pre></div>
  732. </div>
  733. <div class="admonition important">
  734. <p class="first admonition-title">Important</p>
  735. <p class="last">The <code class="docutils literal"><span class="pre">userdata()</span></code> method will NOT return tempdata items.</p>
  736. </div>
  737. <p>Or if you want to be sure that you’re reading “tempdata” (and not any
  738. other kind), you can also use the <code class="docutils literal"><span class="pre">tempdata()</span></code> method:</p>
  739. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">tempdata</span><span class="p">(</span><span class="s1">&#39;item&#39;</span><span class="p">);</span>
  740. </pre></div>
  741. </div>
  742. <p>And of course, if you want to retrieve all existing tempdata:</p>
  743. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">tempdata</span><span class="p">();</span>
  744. </pre></div>
  745. </div>
  746. <div class="admonition note">
  747. <p class="first admonition-title">Note</p>
  748. <p class="last">The <code class="docutils literal"><span class="pre">tempdata()</span></code> method returns NULL if the item cannot be
  749. found.</p>
  750. </div>
  751. <p>If you need to remove a tempdata value before it expires, you can directly
  752. unset it from the <code class="docutils literal"><span class="pre">$_SESSION</span></code> array:</p>
  753. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nb">unset</span><span class="p">(</span><span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">&#39;item&#39;</span><span class="p">]);</span>
  754. </pre></div>
  755. </div>
  756. <p>However, this won’t remove the marker that makes this specific item to be
  757. tempdata (it will be invalidated on the next HTTP request), so if you
  758. intend to reuse that same key in the same request, you’d want to use
  759. <code class="docutils literal"><span class="pre">unset_tempdata()</span></code>:</p>
  760. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">unset_tempdata</span><span class="p">(</span><span class="s1">&#39;item&#39;</span><span class="p">);</span>
  761. </pre></div>
  762. </div>
  763. </div>
  764. <div class="section" id="destroying-a-session">
  765. <h3><a class="toc-backref" href="#id13">Destroying a Session</a><a class="headerlink" href="#destroying-a-session" title="Permalink to this headline">¶</a></h3>
  766. <p>To clear the current session (for example, during a logout), you may
  767. simply use either PHP’s <a class="reference external" href="http://php.net/session_destroy">session_destroy()</a>
  768. function, or the <code class="docutils literal"><span class="pre">sess_destroy()</span></code> method. Both will work in exactly the
  769. same way:</p>
  770. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nb">session_destroy</span><span class="p">();</span>
  771. <span class="c1">// or</span>
  772. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">sess_destroy</span><span class="p">();</span>
  773. </pre></div>
  774. </div>
  775. <div class="admonition note">
  776. <p class="first admonition-title">Note</p>
  777. <p class="last">This must be the last session-related operation that you do
  778. during the same request. All session data (including flashdata and
  779. tempdata) will be destroyed permanently and functions will be
  780. unusable during the same request after you destroy the session.</p>
  781. </div>
  782. </div>
  783. <div class="section" id="accessing-session-metadata">
  784. <h3><a class="toc-backref" href="#id14">Accessing session metadata</a><a class="headerlink" href="#accessing-session-metadata" title="Permalink to this headline">¶</a></h3>
  785. <p>In previous CodeIgniter versions, the session data array included 4 items
  786. by default: ‘session_id’, ‘ip_address’, ‘user_agent’, ‘last_activity’.</p>
  787. <p>This was due to the specifics of how sessions worked, but is now no longer
  788. necessary with our new implementation. However, it may happen that your
  789. application relied on these values, so here are alternative methods of
  790. accessing them:</p>
  791. <blockquote>
  792. <div><ul class="simple">
  793. <li>session_id: <code class="docutils literal"><span class="pre">session_id()</span></code></li>
  794. <li>ip_address: <code class="docutils literal"><span class="pre">$_SERVER['REMOTE_ADDR']</span></code></li>
  795. <li>user_agent: <code class="docutils literal"><span class="pre">$this-&gt;input-&gt;user_agent()</span></code> (unused by sessions)</li>
  796. <li>last_activity: Depends on the storage, no straightforward way. Sorry!</li>
  797. </ul>
  798. </div></blockquote>
  799. </div>
  800. <div class="section" id="session-preferences">
  801. <h3><a class="toc-backref" href="#id15">Session Preferences</a><a class="headerlink" href="#session-preferences" title="Permalink to this headline">¶</a></h3>
  802. <p>CodeIgniter will usually make everything work out of the box. However,
  803. Sessions are a very sensitive component of any application, so some
  804. careful configuration must be done. Please take your time to consider
  805. all of the options and their effects.</p>
  806. <p>You’ll find the following Session related preferences in your
  807. <strong>application/config/config.php</strong> file:</p>
  808. <table border="1" class="docutils">
  809. <colgroup>
  810. <col width="16%" />
  811. <col width="9%" />
  812. <col width="23%" />
  813. <col width="53%" />
  814. </colgroup>
  815. <thead valign="bottom">
  816. <tr class="row-odd"><th class="head">Preference</th>
  817. <th class="head">Default</th>
  818. <th class="head">Options</th>
  819. <th class="head">Description</th>
  820. </tr>
  821. </thead>
  822. <tbody valign="top">
  823. <tr class="row-even"><td><strong>sess_driver</strong></td>
  824. <td>files</td>
  825. <td>files/database/redis/memcached/<em>custom</em></td>
  826. <td>The session storage driver to use.</td>
  827. </tr>
  828. <tr class="row-odd"><td><strong>sess_cookie_name</strong></td>
  829. <td>ci_session</td>
  830. <td>[A-Za-z_-] characters only</td>
  831. <td>The name used for the session cookie.</td>
  832. </tr>
  833. <tr class="row-even"><td><strong>sess_expiration</strong></td>
  834. <td>7200 (2 hours)</td>
  835. <td>Time in seconds (integer)</td>
  836. <td>The number of seconds you would like the session to last.
  837. If you would like a non-expiring session (until browser is closed) set the value to zero: 0</td>
  838. </tr>
  839. <tr class="row-odd"><td><strong>sess_save_path</strong></td>
  840. <td>NULL</td>
  841. <td>None</td>
  842. <td>Specifies the storage location, depends on the driver being used.</td>
  843. </tr>
  844. <tr class="row-even"><td><strong>sess_match_ip</strong></td>
  845. <td>FALSE</td>
  846. <td>TRUE/FALSE (boolean)</td>
  847. <td>Whether to validate the user’s IP address when reading the session cookie.
  848. Note that some ISPs dynamically changes the IP, so if you want a non-expiring session you
  849. will likely set this to FALSE.</td>
  850. </tr>
  851. <tr class="row-odd"><td><strong>sess_time_to_update</strong></td>
  852. <td>300</td>
  853. <td>Time in seconds (integer)</td>
  854. <td>This option controls how often the session class will regenerate itself and create a new
  855. session ID. Setting it to 0 will disable session ID regeneration.</td>
  856. </tr>
  857. <tr class="row-even"><td><strong>sess_regenerate_destroy</strong></td>
  858. <td>FALSE</td>
  859. <td>TRUE/FALSE (boolean)</td>
  860. <td>Whether to destroy session data associated with the old session ID when auto-regenerating
  861. the session ID. When set to FALSE, the data will be later deleted by the garbage collector.</td>
  862. </tr>
  863. </tbody>
  864. </table>
  865. <div class="admonition note">
  866. <p class="first admonition-title">Note</p>
  867. <p class="last">As a last resort, the Session library will try to fetch PHP’s
  868. session related INI settings, as well as legacy CI settings such as
  869. ‘sess_expire_on_close’ when any of the above is not configured.
  870. However, you should never rely on this behavior as it can cause
  871. unexpected results or be changed in the future. Please configure
  872. everything properly.</p>
  873. </div>
  874. <p>In addition to the values above, the cookie and native drivers apply the
  875. following configuration values shared by the <a class="reference internal" href="input.html"><span class="doc">Input</span></a> and
  876. <a class="reference internal" href="security.html"><span class="doc">Security</span></a> classes:</p>
  877. <table border="1" class="docutils">
  878. <colgroup>
  879. <col width="17%" />
  880. <col width="14%" />
  881. <col width="69%" />
  882. </colgroup>
  883. <thead valign="bottom">
  884. <tr class="row-odd"><th class="head">Preference</th>
  885. <th class="head">Default</th>
  886. <th class="head">Description</th>
  887. </tr>
  888. </thead>
  889. <tbody valign="top">
  890. <tr class="row-even"><td><strong>cookie_domain</strong></td>
  891. <td>‘’</td>
  892. <td>The domain for which the session is applicable</td>
  893. </tr>
  894. <tr class="row-odd"><td><strong>cookie_path</strong></td>
  895. <td>/</td>
  896. <td>The path to which the session is applicable</td>
  897. </tr>
  898. <tr class="row-even"><td><strong>cookie_secure</strong></td>
  899. <td>FALSE</td>
  900. <td>Whether to create the session cookie only on encrypted (HTTPS) connections</td>
  901. </tr>
  902. </tbody>
  903. </table>
  904. <div class="admonition note">
  905. <p class="first admonition-title">Note</p>
  906. <p class="last">The ‘cookie_httponly’ setting doesn’t have an effect on sessions.
  907. Instead the HttpOnly parameter is always enabled, for security
  908. reasons. Additionally, the ‘cookie_prefix’ setting is completely
  909. ignored.</p>
  910. </div>
  911. </div>
  912. <div class="section" id="session-drivers">
  913. <h3><a class="toc-backref" href="#id16">Session Drivers</a><a class="headerlink" href="#session-drivers" title="Permalink to this headline">¶</a></h3>
  914. <p>As already mentioned, the Session library comes with 4 drivers, or storage
  915. engines, that you can use:</p>
  916. <blockquote>
  917. <div><ul class="simple">
  918. <li>files</li>
  919. <li>database</li>
  920. <li>redis</li>
  921. <li>memcached</li>
  922. </ul>
  923. </div></blockquote>
  924. <p>By default, the <a class="reference internal" href="#files-driver">Files Driver</a> will be used when a session is initialized,
  925. because it is the most safe choice and is expected to work everywhere
  926. (virtually every environment has a file system).</p>
  927. <p>However, any other driver may be selected via the <code class="docutils literal"><span class="pre">$config['sess_driver']</span></code>
  928. line in your <strong>application/config/config.php</strong> file, if you chose to do so.
  929. Have it in mind though, every driver has different caveats, so be sure to
  930. get yourself familiar with them (below) before you make that choice.</p>
  931. <p>In addition, you may also create and use <a class="reference internal" href="#custom-drivers">Custom Drivers</a>, if the ones
  932. provided by default don’t satisfy your use case.</p>
  933. <div class="admonition note">
  934. <p class="first admonition-title">Note</p>
  935. <p class="last">In previous CodeIgniter versions, a different, “cookie driver”
  936. was the only option and we have received negative feedback on not
  937. providing that option. While we do listen to feedback from the
  938. community, we want to warn you that it was dropped because it is
  939. <strong>unsafe</strong> and we advise you NOT to try to replicate it via a
  940. custom driver.</p>
  941. </div>
  942. <div class="section" id="files-driver">
  943. <h4><a class="toc-backref" href="#id17">Files Driver</a><a class="headerlink" href="#files-driver" title="Permalink to this headline">¶</a></h4>
  944. <p>The ‘files’ driver uses your file system for storing session data.</p>
  945. <p>It can safely be said that it works exactly like PHP’s own default session
  946. implementation, but in case this is an important detail for you, have it
  947. mind that it is in fact not the same code and it has some limitations
  948. (and advantages).</p>
  949. <p>To be more specific, it doesn’t support PHP’s <a class="reference external" href="http://php.net/manual/en/session.configuration.php#ini.session.save-path">directory level and mode
  950. formats used in session.save_path</a>,
  951. and it has most of the options hard-coded for safety. Instead, only
  952. absolute paths are supported for <code class="docutils literal"><span class="pre">$config['sess_save_path']</span></code>.</p>
  953. <p>Another important thing that you should know, is to make sure that you
  954. don’t use a publicly-readable or shared directory for storing your session
  955. files. Make sure that <em>only you</em> have access to see the contents of your
  956. chosen <em>sess_save_path</em> directory. Otherwise, anybody who can do that, can
  957. also steal any of the current sessions (also known as “session fixation”
  958. attack).</p>
  959. <p>On UNIX-like operating systems, this is usually achieved by setting the
  960. 0700 mode permissions on that directory via the <cite>chmod</cite> command, which
  961. allows only the directory’s owner to perform read and write operations on
  962. it. But be careful because the system user <em>running</em> the script is usually
  963. not your own, but something like ‘www-data’ instead, so only setting those
  964. permissions will probable break your application.</p>
  965. <p>Instead, you should do something like this, depending on your environment</p>
  966. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nb">mkdir</span> <span class="o">/&lt;</span><span class="nx">path</span> <span class="nx">to</span> <span class="nx">your</span> <span class="nx">application</span> <span class="nx">directory</span><span class="o">&gt;/</span><span class="nx">sessions</span><span class="o">/</span>
  967. <span class="nb">chmod</span> <span class="mo">0700</span> <span class="o">/&lt;</span><span class="nx">path</span> <span class="nx">to</span> <span class="nx">your</span> <span class="nx">application</span> <span class="nx">directory</span><span class="o">&gt;/</span><span class="nx">sessions</span><span class="o">/</span>
  968. <span class="nb">chown</span> <span class="nx">www</span><span class="o">-</span><span class="nx">data</span> <span class="o">/&lt;</span><span class="nx">path</span> <span class="nx">to</span> <span class="nx">your</span> <span class="nx">application</span> <span class="nx">directory</span><span class="o">&gt;/</span><span class="nx">sessions</span><span class="o">/</span>
  969. </pre></div>
  970. </div>
  971. <div class="section" id="bonus-tip">
  972. <h5><a class="toc-backref" href="#id18">Bonus Tip</a><a class="headerlink" href="#bonus-tip" title="Permalink to this headline">¶</a></h5>
  973. <p>Some of you will probably opt to choose another session driver because
  974. file storage is usually slower. This is only half true.</p>
  975. <p>A very basic test will probably trick you into believing that an SQL
  976. database is faster, but in 99% of the cases, this is only true while you
  977. only have a few current sessions. As the sessions count and server loads
  978. increase - which is the time when it matters - the file system will
  979. consistently outperform almost all relational database setups.</p>
  980. <p>In addition, if performance is your only concern, you may want to look
  981. into using <a class="reference external" href="http://eddmann.com/posts/storing-php-sessions-file-caches-in-memory-using-tmpfs/">tmpfs</a>,
  982. (warning: external resource), which can make your sessions blazing fast.</p>
  983. </div>
  984. </div>
  985. <div class="section" id="database-driver">
  986. <h4><a class="toc-backref" href="#id19">Database Driver</a><a class="headerlink" href="#database-driver" title="Permalink to this headline">¶</a></h4>
  987. <p>The ‘database’ driver uses a relational database such as MySQL or
  988. PostgreSQL to store sessions. This is a popular choice among many users,
  989. because it allows the developer easy access to the session data within
  990. an application - it is just another table in your database.</p>
  991. <p>However, there are some conditions that must be met:</p>
  992. <blockquote>
  993. <div><ul class="simple">
  994. <li>Only your <strong>default</strong> database connection (or the one that you access
  995. as <code class="docutils literal"><span class="pre">$this-&gt;db</span></code> from your controllers) can be used.</li>
  996. <li>You must have the <a class="reference internal" href="../database/query_builder.html"><span class="doc">Query Builder</span></a>
  997. enabled.</li>
  998. <li>You can NOT use a persistent connection.</li>
  999. <li>You can NOT use a connection with the <em>cache_on</em> setting enabled.</li>
  1000. </ul>
  1001. </div></blockquote>
  1002. <p>In order to use the ‘database’ session driver, you must also create this
  1003. table that we already mentioned and then set it as your
  1004. <code class="docutils literal"><span class="pre">$config['sess_save_path']</span></code> value.
  1005. For example, if you would like to use ‘ci_sessions’ as your table name,
  1006. you would do this:</p>
  1007. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;sess_driver&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;database&#39;</span><span class="p">;</span>
  1008. <span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;sess_save_path&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;ci_sessions&#39;</span><span class="p">;</span>
  1009. </pre></div>
  1010. </div>
  1011. <div class="admonition note">
  1012. <p class="first admonition-title">Note</p>
  1013. <p class="last">If you’ve upgraded from a previous version of CodeIgniter and
  1014. you don’t have ‘sess_save_path’ configured, then the Session
  1015. library will look for the old ‘sess_table_name’ setting and use
  1016. it instead. Please don’t rely on this behavior as it will get
  1017. removed in the future.</p>
  1018. </div>
  1019. <p>And then of course, create the database table …</p>
  1020. <p>For MySQL:</p>
  1021. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nx">CREATE</span> <span class="nx">TABLE</span> <span class="k">IF</span> <span class="k">NOT</span> <span class="nx">EXISTS</span> <span class="sb">`ci_sessions`</span> <span class="p">(</span>
  1022. <span class="sb">`id`</span> <span class="nx">varchar</span><span class="p">(</span><span class="mi">128</span><span class="p">)</span> <span class="k">NOT</span> <span class="k">NULL</span><span class="p">,</span>
  1023. <span class="sb">`ip_address`</span> <span class="nx">varchar</span><span class="p">(</span><span class="mi">45</span><span class="p">)</span> <span class="k">NOT</span> <span class="k">NULL</span><span class="p">,</span>
  1024. <span class="sb">`timestamp`</span> <span class="nx">int</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span> <span class="nx">unsigned</span> <span class="k">DEFAULT</span> <span class="mi">0</span> <span class="k">NOT</span> <span class="k">NULL</span><span class="p">,</span>
  1025. <span class="sb">`data`</span> <span class="nx">blob</span> <span class="k">NOT</span> <span class="k">NULL</span><span class="p">,</span>
  1026. <span class="nx">KEY</span> <span class="sb">`ci_sessions_timestamp`</span> <span class="p">(</span><span class="sb">`timestamp`</span><span class="p">)</span>
  1027. <span class="p">);</span>
  1028. </pre></div>
  1029. </div>
  1030. <p>For PostgreSQL:</p>
  1031. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nx">CREATE</span> <span class="nx">TABLE</span> <span class="s2">&quot;ci_sessions&quot;</span> <span class="p">(</span>
  1032. <span class="s2">&quot;id&quot;</span> <span class="nx">varchar</span><span class="p">(</span><span class="mi">128</span><span class="p">)</span> <span class="k">NOT</span> <span class="k">NULL</span><span class="p">,</span>
  1033. <span class="s2">&quot;ip_address&quot;</span> <span class="nx">varchar</span><span class="p">(</span><span class="mi">45</span><span class="p">)</span> <span class="k">NOT</span> <span class="k">NULL</span><span class="p">,</span>
  1034. <span class="s2">&quot;timestamp&quot;</span> <span class="nx">bigint</span> <span class="k">DEFAULT</span> <span class="mi">0</span> <span class="k">NOT</span> <span class="k">NULL</span><span class="p">,</span>
  1035. <span class="s2">&quot;data&quot;</span> <span class="nx">text</span> <span class="k">DEFAULT</span> <span class="s1">&#39;&#39;</span> <span class="k">NOT</span> <span class="k">NULL</span>
  1036. <span class="p">);</span>
  1037. <span class="nx">CREATE</span> <span class="nx">INDEX</span> <span class="s2">&quot;ci_sessions_timestamp&quot;</span> <span class="nx">ON</span> <span class="s2">&quot;ci_sessions&quot;</span> <span class="p">(</span><span class="s2">&quot;timestamp&quot;</span><span class="p">);</span>
  1038. </pre></div>
  1039. </div>
  1040. <p>You will also need to add a PRIMARY KEY <strong>depending on your ‘sess_match_ip’
  1041. setting</strong>. The examples below work both on MySQL and PostgreSQL:</p>
  1042. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="c1">// When sess_match_ip = TRUE</span>
  1043. <span class="nx">ALTER</span> <span class="nx">TABLE</span> <span class="nx">ci_sessions</span> <span class="nx">ADD</span> <span class="nx">PRIMARY</span> <span class="nx">KEY</span> <span class="p">(</span><span class="nx">id</span><span class="p">,</span> <span class="nx">ip_address</span><span class="p">);</span>
  1044. <span class="c1">// When sess_match_ip = FALSE</span>
  1045. <span class="nx">ALTER</span> <span class="nx">TABLE</span> <span class="nx">ci_sessions</span> <span class="nx">ADD</span> <span class="nx">PRIMARY</span> <span class="nx">KEY</span> <span class="p">(</span><span class="nx">id</span><span class="p">);</span>
  1046. <span class="c1">// To drop a previously created primary key (use when changing the setting)</span>
  1047. <span class="nx">ALTER</span> <span class="nx">TABLE</span> <span class="nx">ci_sessions</span> <span class="nx">DROP</span> <span class="nx">PRIMARY</span> <span class="nx">KEY</span><span class="p">;</span>
  1048. </pre></div>
  1049. </div>
  1050. <div class="admonition important">
  1051. <p class="first admonition-title">Important</p>
  1052. <p class="last">Only MySQL and PostgreSQL databases are officially
  1053. supported, due to lack of advisory locking mechanisms on other
  1054. platforms. Using sessions without locks can cause all sorts of
  1055. problems, especially with heavy usage of AJAX, and we will not
  1056. support such cases. Use <code class="docutils literal"><span class="pre">session_write_close()</span></code> after you’ve
  1057. done processing session data if you’re having performance
  1058. issues.</p>
  1059. </div>
  1060. </div>
  1061. <div class="section" id="redis-driver">
  1062. <h4><a class="toc-backref" href="#id20">Redis Driver</a><a class="headerlink" href="#redis-driver" title="Permalink to this headline">¶</a></h4>
  1063. <div class="admonition note">
  1064. <p class="first admonition-title">Note</p>
  1065. <p class="last">Since Redis doesn’t have a locking mechanism exposed, locks for
  1066. this driver are emulated by a separate value that is kept for up
  1067. to 300 seconds.</p>
  1068. </div>
  1069. <p>Redis is a storage engine typically used for caching and popular because
  1070. of its high performance, which is also probably your reason to use the
  1071. ‘redis’ session driver.</p>
  1072. <p>The downside is that it is not as ubiquitous as relational databases and
  1073. requires the <a class="reference external" href="https://github.com/phpredis/phpredis">phpredis</a> PHP
  1074. extension to be installed on your system, and that one doesn’t come
  1075. bundled with PHP.
  1076. Chances are, you’re only be using the ‘redis’ driver only if you’re already
  1077. both familiar with Redis and using it for other purposes.</p>
  1078. <p>Just as with the ‘files’ and ‘database’ drivers, you must also configure
  1079. the storage location for your sessions via the
  1080. <code class="docutils literal"><span class="pre">$config['sess_save_path']</span></code> setting.
  1081. The format here is a bit different and complicated at the same time. It is
  1082. best explained by the <em>phpredis</em> extension’s README file, so we’ll simply
  1083. link you to it:</p>
  1084. <blockquote>
  1085. <div><a class="reference external" href="https://github.com/phpredis/phpredis#php-session-handler">https://github.com/phpredis/phpredis#php-session-handler</a></div></blockquote>
  1086. <div class="admonition warning">
  1087. <p class="first admonition-title">Warning</p>
  1088. <p class="last">CodeIgniter’s Session library does NOT use the actual ‘redis’
  1089. <code class="docutils literal"><span class="pre">session.save_handler</span></code>. Take note <strong>only</strong> of the path format in
  1090. the link above.</p>
  1091. </div>
  1092. <p>For the most common case however, a simple <code class="docutils literal"><span class="pre">host:port</span></code> pair should be
  1093. sufficient:</p>
  1094. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;sess_driver&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;redis&#39;</span><span class="p">;</span>
  1095. <span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;sess_save_path&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;tcp://localhost:6379&#39;</span><span class="p">;</span>
  1096. </pre></div>
  1097. </div>
  1098. </div>
  1099. <div class="section" id="memcached-driver">
  1100. <h4><a class="toc-backref" href="#id21">Memcached Driver</a><a class="headerlink" href="#memcached-driver" title="Permalink to this headline">¶</a></h4>
  1101. <div class="admonition note">
  1102. <p class="first admonition-title">Note</p>
  1103. <p class="last">Since Memcache doesn’t have a locking mechanism exposed, locks
  1104. for this driver are emulated by a separate value that is kept for
  1105. up to 300 seconds.</p>
  1106. </div>
  1107. <p>The ‘memcached’ driver is very similar to the ‘redis’ one in all of its
  1108. properties, except perhaps for availability, because PHP’s <a class="reference external" href="http://php.net/memcached">Memcached</a> extension is distributed via PECL and some
  1109. Linux distrubutions make it available as an easy to install package.</p>
  1110. <p>Other than that, and without any intentional bias towards Redis, there’s
  1111. not much different to be said about Memcached - it is also a popular
  1112. product that is usually used for caching and famed for its speed.</p>
  1113. <p>However, it is worth noting that the only guarantee given by Memcached
  1114. is that setting value X to expire after Y seconds will result in it being
  1115. deleted after Y seconds have passed (but not necessarily that it won’t
  1116. expire earlier than that time). This happens very rarely, but should be
  1117. considered as it may result in loss of sessions.</p>
  1118. <p>The <code class="docutils literal"><span class="pre">$config['sess_save_path']</span></code> format is fairly straightforward here,
  1119. being just a <code class="docutils literal"><span class="pre">host:port</span></code> pair:</p>
  1120. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;sess_driver&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;memcached&#39;</span><span class="p">;</span>
  1121. <span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;sess_save_path&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;localhost:11211&#39;</span><span class="p">;</span>
  1122. </pre></div>
  1123. </div>
  1124. <div class="section" id="id1">
  1125. <h5><a class="toc-backref" href="#id22">Bonus Tip</a><a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h5>
  1126. <p>Multi-server configuration with an optional <em>weight</em> parameter as the
  1127. third colon-separated (<code class="docutils literal"><span class="pre">:weight</span></code>) value is also supported, but we have
  1128. to note that we haven’t tested if that is reliable.</p>
  1129. <p>If you want to experiment with this feature (on your own risk), simply
  1130. separate the multiple server paths with commas:</p>
  1131. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="c1">// localhost will be given higher priority (5) here,</span>
  1132. <span class="c1">// compared to 192.0.2.1 with a weight of 1.</span>
  1133. <span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;sess_save_path&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;localhost:11211:5,192.0.2.1:11211:1&#39;</span><span class="p">;</span>
  1134. </pre></div>
  1135. </div>
  1136. </div>
  1137. </div>
  1138. <div class="section" id="custom-drivers">
  1139. <h4><a class="toc-backref" href="#id23">Custom Drivers</a><a class="headerlink" href="#custom-drivers" title="Permalink to this headline">¶</a></h4>
  1140. <p>You may also create your own, custom session drivers. However, have it in
  1141. mind that this is typically not an easy task, as it takes a lot of
  1142. knowledge to do it properly.</p>
  1143. <p>You need to know not only how sessions work in general, but also how they
  1144. work specifically in PHP, how the underlying storage mechanism works, how
  1145. to handle concurrency, avoid deadlocks (but NOT through lack of locks) and
  1146. last but not least - how to handle the potential security issues, which
  1147. is far from trivial.</p>
  1148. <p>Long story short - if you don’t know how to do that already in raw PHP,
  1149. you shouldn’t be trying to do it within CodeIgniter either. You’ve been
  1150. warned.</p>
  1151. <p>If you only want to add some extra functionality to your sessions, just
  1152. extend the base Session class, which is a lot more easier. Read the
  1153. <a class="reference internal" href="../general/creating_libraries.html"><span class="doc">Creating Libraries</span></a> article to
  1154. learn how to do that.</p>
  1155. <p>Now, to the point - there are three general rules that you must follow
  1156. when creating a session driver for CodeIgniter:</p>
  1157. <blockquote>
  1158. <div><ul>
  1159. <li><p class="first">Put your driver’s file under <strong>application/libraries/Session/drivers/</strong>
  1160. and follow the naming conventions used by the Session class.</p>
  1161. <p>For example, if you were to create a ‘dummy’ driver, you would have
  1162. a <code class="docutils literal"><span class="pre">Session_dummy_driver</span></code> class name, that is declared in
  1163. <em>application/libraries/Session/drivers/Session_dummy_driver.php</em>.</p>
  1164. </li>
  1165. <li><p class="first">Extend the <code class="docutils literal"><span class="pre">CI_Session_driver</span></code> class.</p>
  1166. <p>This is just a basic class with a few internal helper methods. It is
  1167. also extendable like any other library, if you really need to do that,
  1168. but we are not going to explain how … if you’re familiar with how
  1169. class extensions/overrides work in CI, then you already know how to do
  1170. it. If not, well, you shouldn’t be doing it in the first place.</p>
  1171. </li>
  1172. <li><p class="first">Implement the <a class="reference external" href="http://php.net/sessionhandlerinterface">SessionHandlerInterface</a> interface.</p>
  1173. <div class="admonition note">
  1174. <p class="first admonition-title">Note</p>
  1175. <p class="last">You may notice that <code class="docutils literal"><span class="pre">SessionHandlerInterface</span></code> is provided
  1176. by PHP since version 5.4.0. CodeIgniter will automatically declare
  1177. the same interface if you’re running an older PHP version.</p>
  1178. </div>
  1179. <p>The link will explain why and how.</p>
  1180. </li>
  1181. </ul>
  1182. </div></blockquote>
  1183. <p>So, based on our ‘dummy’ driver example above, you’d end up with something
  1184. like this:</p>
  1185. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="c1">// application/libraries/Session/drivers/Session_dummy_driver.php:</span>
  1186. <span class="k">class</span> <span class="nc">CI_Session_dummy_driver</span> <span class="k">extends</span> <span class="nx">CI_Session_driver</span> <span class="k">implements</span> <span class="nx">SessionHandlerInterface</span>
  1187. <span class="p">{</span>
  1188. <span class="k">public</span> <span class="k">function</span> <span class="nf">__construct</span><span class="p">(</span><span class="o">&amp;</span><span class="nv">$params</span><span class="p">)</span>
  1189. <span class="p">{</span>
  1190. <span class="c1">// DO NOT forget this</span>
  1191. <span class="k">parent</span><span class="o">::</span><span class="na">__construct</span><span class="p">(</span><span class="nv">$params</span><span class="p">);</span>
  1192. <span class="c1">// Configuration &amp; other initializations</span>
  1193. <span class="p">}</span>
  1194. <span class="k">public</span> <span class="k">function</span> <span class="nf">open</span><span class="p">(</span><span class="nv">$save_path</span><span class="p">,</span> <span class="nv">$name</span><span class="p">)</span>
  1195. <span class="p">{</span>
  1196. <span class="c1">// Initialize storage mechanism (connection)</span>
  1197. <span class="p">}</span>
  1198. <span class="k">public</span> <span class="k">function</span> <span class="nf">read</span><span class="p">(</span><span class="nv">$session_id</span><span class="p">)</span>
  1199. <span class="p">{</span>
  1200. <span class="c1">// Read session data (if exists), acquire locks</span>
  1201. <span class="p">}</span>
  1202. <span class="k">public</span> <span class="k">function</span> <span class="nf">write</span><span class="p">(</span><span class="nv">$session_id</span><span class="p">,</span> <span class="nv">$session_data</span><span class="p">)</span>
  1203. <span class="p">{</span>
  1204. <span class="c1">// Create / update session data (it might not exist!)</span>
  1205. <span class="p">}</span>
  1206. <span class="k">public</span> <span class="k">function</span> <span class="nf">close</span><span class="p">()</span>
  1207. <span class="p">{</span>
  1208. <span class="c1">// Free locks, close connections / streams / etc.</span>
  1209. <span class="p">}</span>
  1210. <span class="k">public</span> <span class="k">function</span> <span class="nf">destroy</span><span class="p">(</span><span class="nv">$session_id</span><span class="p">)</span>
  1211. <span class="p">{</span>
  1212. <span class="c1">// Call close() method &amp; destroy data for current session (order may differ)</span>
  1213. <span class="p">}</span>
  1214. <span class="k">public</span> <span class="k">function</span> <span class="nf">gc</span><span class="p">(</span><span class="nv">$maxlifetime</span><span class="p">)</span>
  1215. <span class="p">{</span>
  1216. <span class="c1">// Erase data for expired sessions</span>
  1217. <span class="p">}</span>
  1218. <span class="p">}</span>
  1219. </pre></div>
  1220. </div>
  1221. <p>If you’ve done everything properly, you can now set your <em>sess_driver</em>
  1222. configuration value to ‘dummy’ and use your own driver. Congratulations!</p>
  1223. </div>
  1224. </div>
  1225. </div>
  1226. <div class="section" id="class-reference">
  1227. <h2><a class="toc-backref" href="#id24">Class Reference</a><a class="headerlink" href="#class-reference" title="Permalink to this headline">¶</a></h2>
  1228. <dl class="class">
  1229. <dt id="CI_Session">
  1230. <em class="property">class </em><code class="descname">CI_Session</code><a class="headerlink" href="#CI_Session" title="Permalink to this definition">¶</a></dt>
  1231. <dd><dl class="method">
  1232. <dt id="CI_Session::userdata">
  1233. <code class="descname">userdata</code><span class="sig-paren">(</span><span class="optional">[</span><em>$key = NULL</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Session::userdata" title="Permalink to this definition">¶</a></dt>
  1234. <dd><table class="docutils field-list" frame="void" rules="none">
  1235. <col class="field-name" />
  1236. <col class="field-body" />
  1237. <tbody valign="top">
  1238. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  1239. <li><strong>$key</strong> (<em>mixed</em>) – Session item key or NULL</li>
  1240. </ul>
  1241. </td>
  1242. </tr>
  1243. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Value of the specified item key, or an array of all userdata</p>
  1244. </td>
  1245. </tr>
  1246. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">mixed</p>
  1247. </td>
  1248. </tr>
  1249. </tbody>
  1250. </table>
  1251. <p>Gets the value for a specific <code class="docutils literal"><span class="pre">$_SESSION</span></code> item, or an
  1252. array of all “userdata” items if not key was specified.</p>
  1253. <div class="admonition note">
  1254. <p class="first admonition-title">Note</p>
  1255. <p class="last">This is a legacy method kept only for backwards
  1256. compatibility with older applications. You should
  1257. directly access <code class="docutils literal"><span class="pre">$_SESSION</span></code> instead.</p>
  1258. </div>
  1259. </dd></dl>
  1260. <dl class="method">
  1261. <dt id="CI_Session::all_userdata">
  1262. <code class="descname">all_userdata</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Session::all_userdata" title="Permalink to this definition">¶</a></dt>
  1263. <dd><table class="docutils field-list" frame="void" rules="none">
  1264. <col class="field-name" />
  1265. <col class="field-body" />
  1266. <tbody valign="top">
  1267. <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">An array of all userdata</td>
  1268. </tr>
  1269. <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">array</td>
  1270. </tr>
  1271. </tbody>
  1272. </table>
  1273. <p>Returns an array containing all “userdata” items.</p>
  1274. <div class="admonition note">
  1275. <p class="first admonition-title">Note</p>
  1276. <p class="last">This method is DEPRECATED. Use <code class="docutils literal"><span class="pre">userdata()</span></code>
  1277. with no parameters instead.</p>
  1278. </div>
  1279. </dd></dl>
  1280. <dl class="method">
  1281. <dt>
  1282. <code class="descname">&amp;get_userdata()</code></dt>
  1283. <dd><table class="docutils field-list" frame="void" rules="none">
  1284. <col class="field-name" />
  1285. <col class="field-body" />
  1286. <tbody valign="top">
  1287. <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">A reference to <code class="docutils literal"><span class="pre">$_SESSION</span></code></td>
  1288. </tr>
  1289. <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">array</td>
  1290. </tr>
  1291. </tbody>
  1292. </table>
  1293. <p>Returns a reference to the <code class="docutils literal"><span class="pre">$_SESSION</span></code> array.</p>
  1294. <div class="admonition note">
  1295. <p class="first admonition-title">Note</p>
  1296. <p class="last">This is a legacy method kept only for backwards
  1297. compatibility with older applications.</p>
  1298. </div>
  1299. </dd></dl>
  1300. <dl class="method">
  1301. <dt id="CI_Session::has_userdata">
  1302. <code class="descname">has_userdata</code><span class="sig-paren">(</span><em>$key</em><span class="sig-paren">)</span><a class="headerlink" href="#CI_Session::has_userdata" title="Permalink to this definition">¶</a></dt>
  1303. <dd><table class="docutils field-list" frame="void" rules="none">
  1304. <col class="field-name" />
  1305. <col class="field-body" />
  1306. <tbody valign="top">
  1307. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  1308. <li><strong>$key</strong> (<em>string</em>) – Session item key</li>
  1309. </ul>
  1310. </td>
  1311. </tr>
  1312. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">TRUE if the specified key exists, FALSE if not</p>
  1313. </td>
  1314. </tr>
  1315. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
  1316. </td>
  1317. </tr>
  1318. </tbody>
  1319. </table>
  1320. <p>Checks if an item exists in <code class="docutils literal"><span class="pre">$_SESSION</span></code>.</p>
  1321. <div class="admonition note">
  1322. <p class="first admonition-title">Note</p>
  1323. <p class="last">This is a legacy method kept only for backwards
  1324. compatibility with older applications. It is just
  1325. an alias for <code class="docutils literal"><span class="pre">isset($_SESSION[$key])</span></code> - please
  1326. use that instead.</p>
  1327. </div>
  1328. </dd></dl>
  1329. <dl class="method">
  1330. <dt id="CI_Session::set_userdata">
  1331. <code class="descname">set_userdata</code><span class="sig-paren">(</span><em>$data</em><span class="optional">[</span>, <em>$value = NULL</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Session::set_userdata" title="Permalink to this definition">¶</a></dt>
  1332. <dd><table class="docutils field-list" frame="void" rules="none">
  1333. <col class="field-name" />
  1334. <col class="field-body" />
  1335. <tbody valign="top">
  1336. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  1337. <li><strong>$data</strong> (<em>mixed</em>) – An array of key/value pairs to set as session data, or the key for a single item</li>
  1338. <li><strong>$value</strong> (<em>mixed</em>) – The value to set for a specific session item, if $data is a key</li>
  1339. </ul>
  1340. </td>
  1341. </tr>
  1342. <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">void</p>
  1343. </td>
  1344. </tr>
  1345. </tbody>
  1346. </table>
  1347. <p>Assigns data to the <code class="docutils literal"><span class="pre">$_SESSION</span></code> superglobal.</p>
  1348. <div class="admonition note">
  1349. <p class="first admonition-title">Note</p>
  1350. <p class="last">This is a legacy method kept only for backwards
  1351. compatibility with older applications.</p>
  1352. </div>
  1353. </dd></dl>
  1354. <dl class="method">
  1355. <dt id="CI_Session::unset_userdata">
  1356. <code class="descname">unset_userdata</code><span class="sig-paren">(</span><em>$key</em><span class="sig-paren">)</span><a class="headerlink" href="#CI_Session::unset_userdata" title="Permalink to this definition">¶</a></dt>
  1357. <dd><table class="docutils field-list" frame="void" rules="none">
  1358. <col class="field-name" />
  1359. <col class="field-body" />
  1360. <tbody valign="top">
  1361. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  1362. <li><strong>$key</strong> (<em>mixed</em>) – Key for the session data item to unset, or an array of multiple keys</li>
  1363. </ul>
  1364. </td>
  1365. </tr>
  1366. <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">void</p>
  1367. </td>
  1368. </tr>
  1369. </tbody>
  1370. </table>
  1371. <p>Unsets the specified key(s) from the <code class="docutils literal"><span class="pre">$_SESSION</span></code>
  1372. superglobal.</p>
  1373. <div class="admonition note">
  1374. <p class="first admonition-title">Note</p>
  1375. <p class="last">This is a legacy method kept only for backwards
  1376. compatibility with older applications. It is just
  1377. an alias for <code class="docutils literal"><span class="pre">unset($_SESSION[$key])</span></code> - please
  1378. use that instead.</p>
  1379. </div>
  1380. </dd></dl>
  1381. <dl class="method">
  1382. <dt id="CI_Session::mark_as_flash">
  1383. <code class="descname">mark_as_flash</code><span class="sig-paren">(</span><em>$key</em><span class="sig-paren">)</span><a class="headerlink" href="#CI_Session::mark_as_flash" title="Permalink to this definition">¶</a></dt>
  1384. <dd><table class="docutils field-list" frame="void" rules="none">
  1385. <col class="field-name" />
  1386. <col class="field-body" />
  1387. <tbody valign="top">
  1388. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  1389. <li><strong>$key</strong> (<em>mixed</em>) – Key to mark as flashdata, or an array of multiple keys</li>
  1390. </ul>
  1391. </td>
  1392. </tr>
  1393. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">TRUE on success, FALSE on failure</p>
  1394. </td>
  1395. </tr>
  1396. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
  1397. </td>
  1398. </tr>
  1399. </tbody>
  1400. </table>
  1401. <p>Marks a <code class="docutils literal"><span class="pre">$_SESSION</span></code> item key (or multiple ones) as
  1402. “flashdata”.</p>
  1403. </dd></dl>
  1404. <dl class="method">
  1405. <dt id="CI_Session::get_flash_keys">
  1406. <code class="descname">get_flash_keys</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Session::get_flash_keys" title="Permalink to this definition">¶</a></dt>
  1407. <dd><table class="docutils field-list" frame="void" rules="none">
  1408. <col class="field-name" />
  1409. <col class="field-body" />
  1410. <tbody valign="top">
  1411. <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Array containing the keys of all “flashdata” items.</td>
  1412. </tr>
  1413. <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">array</td>
  1414. </tr>
  1415. </tbody>
  1416. </table>
  1417. <p>Gets a list of all <code class="docutils literal"><span class="pre">$_SESSION</span></code> that have been marked as
  1418. “flashdata”.</p>
  1419. </dd></dl>
  1420. <dl class="method">
  1421. <dt id="CI_Session::unmark_flash">
  1422. <code class="descname">unmark_flash</code><span class="sig-paren">(</span><em>$key</em><span class="sig-paren">)</span><a class="headerlink" href="#CI_Session::unmark_flash" title="Permalink to this definition">¶</a></dt>
  1423. <dd><table class="docutils field-list" frame="void" rules="none">
  1424. <col class="field-name" />
  1425. <col class="field-body" />
  1426. <tbody valign="top">
  1427. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  1428. <li><strong>$key</strong> (<em>mixed</em>) – Key to be un-marked as flashdata, or an array of multiple keys</li>
  1429. </ul>
  1430. </td>
  1431. </tr>
  1432. <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">void</p>
  1433. </td>
  1434. </tr>
  1435. </tbody>
  1436. </table>
  1437. <p>Unmarks a <code class="docutils literal"><span class="pre">$_SESSION</span></code> item key (or multiple ones) as
  1438. “flashdata”.</p>
  1439. </dd></dl>
  1440. <dl class="method">
  1441. <dt id="CI_Session::flashdata">
  1442. <code class="descname">flashdata</code><span class="sig-paren">(</span><span class="optional">[</span><em>$key = NULL</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Session::flashdata" title="Permalink to this definition">¶</a></dt>
  1443. <dd><table class="docutils field-list" frame="void" rules="none">
  1444. <col class="field-name" />
  1445. <col class="field-body" />
  1446. <tbody valign="top">
  1447. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  1448. <li><strong>$key</strong> (<em>mixed</em>) – Flashdata item key or NULL</li>
  1449. </ul>
  1450. </td>
  1451. </tr>
  1452. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Value of the specified item key, or an array of all flashdata</p>
  1453. </td>
  1454. </tr>
  1455. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">mixed</p>
  1456. </td>
  1457. </tr>
  1458. </tbody>
  1459. </table>
  1460. <p>Gets the value for a specific <code class="docutils literal"><span class="pre">$_SESSION</span></code> item that has
  1461. been marked as “flashdata”, or an array of all “flashdata”
  1462. items if no key was specified.</p>
  1463. <div class="admonition note">
  1464. <p class="first admonition-title">Note</p>
  1465. <p class="last">This is a legacy method kept only for backwards
  1466. compatibility with older applications. You should
  1467. directly access <code class="docutils literal"><span class="pre">$_SESSION</span></code> instead.</p>
  1468. </div>
  1469. </dd></dl>
  1470. <dl class="method">
  1471. <dt id="CI_Session::keep_flashdata">
  1472. <code class="descname">keep_flashdata</code><span class="sig-paren">(</span><em>$key</em><span class="sig-paren">)</span><a class="headerlink" href="#CI_Session::keep_flashdata" title="Permalink to this definition">¶</a></dt>
  1473. <dd><table class="docutils field-list" frame="void" rules="none">
  1474. <col class="field-name" />
  1475. <col class="field-body" />
  1476. <tbody valign="top">
  1477. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  1478. <li><strong>$key</strong> (<em>mixed</em>) – Flashdata key to keep, or an array of multiple keys</li>
  1479. </ul>
  1480. </td>
  1481. </tr>
  1482. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">TRUE on success, FALSE on failure</p>
  1483. </td>
  1484. </tr>
  1485. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
  1486. </td>
  1487. </tr>
  1488. </tbody>
  1489. </table>
  1490. <p>Retains the specified session data key(s) as “flashdata”
  1491. through the next request.</p>
  1492. <div class="admonition note">
  1493. <p class="first admonition-title">Note</p>
  1494. <p class="last">This is a legacy method kept only for backwards
  1495. compatibility with older applications. It is just
  1496. an alias for the <code class="docutils literal"><span class="pre">mark_as_flash()</span></code> method.</p>
  1497. </div>
  1498. </dd></dl>
  1499. <dl class="method">
  1500. <dt id="CI_Session::set_flashdata">
  1501. <code class="descname">set_flashdata</code><span class="sig-paren">(</span><em>$data</em><span class="optional">[</span>, <em>$value = NULL</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Session::set_flashdata" title="Permalink to this definition">¶</a></dt>
  1502. <dd><table class="docutils field-list" frame="void" rules="none">
  1503. <col class="field-name" />
  1504. <col class="field-body" />
  1505. <tbody valign="top">
  1506. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  1507. <li><strong>$data</strong> (<em>mixed</em>) – An array of key/value pairs to set as flashdata, or the key for a single item</li>
  1508. <li><strong>$value</strong> (<em>mixed</em>) – The value to set for a specific session item, if $data is a key</li>
  1509. </ul>
  1510. </td>
  1511. </tr>
  1512. <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">void</p>
  1513. </td>
  1514. </tr>
  1515. </tbody>
  1516. </table>
  1517. <p>Assigns data to the <code class="docutils literal"><span class="pre">$_SESSION</span></code> superglobal and marks it
  1518. as “flashdata”.</p>
  1519. <div class="admonition note">
  1520. <p class="first admonition-title">Note</p>
  1521. <p class="last">This is a legacy method kept only for backwards
  1522. compatibility with older applications.</p>
  1523. </div>
  1524. </dd></dl>
  1525. <dl class="method">
  1526. <dt id="CI_Session::mark_as_temp">
  1527. <code class="descname">mark_as_temp</code><span class="sig-paren">(</span><em>$key</em><span class="optional">[</span>, <em>$ttl = 300</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Session::mark_as_temp" title="Permalink to this definition">¶</a></dt>
  1528. <dd><table class="docutils field-list" frame="void" rules="none">
  1529. <col class="field-name" />
  1530. <col class="field-body" />
  1531. <tbody valign="top">
  1532. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  1533. <li><strong>$key</strong> (<em>mixed</em>) – Key to mark as tempdata, or an array of multiple keys</li>
  1534. <li><strong>$ttl</strong> (<em>int</em>) – Time-to-live value for the tempdata, in seconds</li>
  1535. </ul>
  1536. </td>
  1537. </tr>
  1538. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">TRUE on success, FALSE on failure</p>
  1539. </td>
  1540. </tr>
  1541. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
  1542. </td>
  1543. </tr>
  1544. </tbody>
  1545. </table>
  1546. <p>Marks a <code class="docutils literal"><span class="pre">$_SESSION</span></code> item key (or multiple ones) as
  1547. “tempdata”.</p>
  1548. </dd></dl>
  1549. <dl class="method">
  1550. <dt id="CI_Session::get_temp_keys">
  1551. <code class="descname">get_temp_keys</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Session::get_temp_keys" title="Permalink to this definition">¶</a></dt>
  1552. <dd><table class="docutils field-list" frame="void" rules="none">
  1553. <col class="field-name" />
  1554. <col class="field-body" />
  1555. <tbody valign="top">
  1556. <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Array containing the keys of all “tempdata” items.</td>
  1557. </tr>
  1558. <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">array</td>
  1559. </tr>
  1560. </tbody>
  1561. </table>
  1562. <p>Gets a list of all <code class="docutils literal"><span class="pre">$_SESSION</span></code> that have been marked as
  1563. “tempdata”.</p>
  1564. </dd></dl>
  1565. <dl class="method">
  1566. <dt id="CI_Session::unmark_temp">
  1567. <code class="descname">unmark_temp</code><span class="sig-paren">(</span><em>$key</em><span class="sig-paren">)</span><a class="headerlink" href="#CI_Session::unmark_temp" title="Permalink to this definition">¶</a></dt>
  1568. <dd><table class="docutils field-list" frame="void" rules="none">
  1569. <col class="field-name" />
  1570. <col class="field-body" />
  1571. <tbody valign="top">
  1572. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  1573. <li><strong>$key</strong> (<em>mixed</em>) – Key to be un-marked as tempdata, or an array of multiple keys</li>
  1574. </ul>
  1575. </td>
  1576. </tr>
  1577. <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">void</p>
  1578. </td>
  1579. </tr>
  1580. </tbody>
  1581. </table>
  1582. <p>Unmarks a <code class="docutils literal"><span class="pre">$_SESSION</span></code> item key (or multiple ones) as
  1583. “tempdata”.</p>
  1584. </dd></dl>
  1585. <dl class="method">
  1586. <dt id="CI_Session::tempdata">
  1587. <code class="descname">tempdata</code><span class="sig-paren">(</span><span class="optional">[</span><em>$key = NULL</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Session::tempdata" title="Permalink to this definition">¶</a></dt>
  1588. <dd><table class="docutils field-list" frame="void" rules="none">
  1589. <col class="field-name" />
  1590. <col class="field-body" />
  1591. <tbody valign="top">
  1592. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  1593. <li><strong>$key</strong> (<em>mixed</em>) – Tempdata item key or NULL</li>
  1594. </ul>
  1595. </td>
  1596. </tr>
  1597. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Value of the specified item key, or an array of all tempdata</p>
  1598. </td>
  1599. </tr>
  1600. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">mixed</p>
  1601. </td>
  1602. </tr>
  1603. </tbody>
  1604. </table>
  1605. <p>Gets the value for a specific <code class="docutils literal"><span class="pre">$_SESSION</span></code> item that has
  1606. been marked as “tempdata”, or an array of all “tempdata”
  1607. items if no key was specified.</p>
  1608. <div class="admonition note">
  1609. <p class="first admonition-title">Note</p>
  1610. <p class="last">This is a legacy method kept only for backwards
  1611. compatibility with older applications. You should
  1612. directly access <code class="docutils literal"><span class="pre">$_SESSION</span></code> instead.</p>
  1613. </div>
  1614. </dd></dl>
  1615. <dl class="method">
  1616. <dt id="CI_Session::set_tempdata">
  1617. <code class="descname">set_tempdata</code><span class="sig-paren">(</span><em>$data</em><span class="optional">[</span>, <em>$value = NULL</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Session::set_tempdata" title="Permalink to this definition">¶</a></dt>
  1618. <dd><table class="docutils field-list" frame="void" rules="none">
  1619. <col class="field-name" />
  1620. <col class="field-body" />
  1621. <tbody valign="top">
  1622. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  1623. <li><strong>$data</strong> (<em>mixed</em>) – An array of key/value pairs to set as tempdata, or the key for a single item</li>
  1624. <li><strong>$value</strong> (<em>mixed</em>) – The value to set for a specific session item, if $data is a key</li>
  1625. <li><strong>$ttl</strong> (<em>int</em>) – Time-to-live value for the tempdata item(s), in seconds</li>
  1626. </ul>
  1627. </td>
  1628. </tr>
  1629. <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">void</p>
  1630. </td>
  1631. </tr>
  1632. </tbody>
  1633. </table>
  1634. <p>Assigns data to the <code class="docutils literal"><span class="pre">$_SESSION</span></code> superglobal and marks it
  1635. as “tempdata”.</p>
  1636. <div class="admonition note">
  1637. <p class="first admonition-title">Note</p>
  1638. <p class="last">This is a legacy method kept only for backwards
  1639. compatibility with older applications.</p>
  1640. </div>
  1641. </dd></dl>
  1642. <dl class="method">
  1643. <dt id="CI_Session::sess_regenerate">
  1644. <code class="descname">sess_regenerate</code><span class="sig-paren">(</span><span class="optional">[</span><em>$destroy = FALSE</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Session::sess_regenerate" title="Permalink to this definition">¶</a></dt>
  1645. <dd><table class="docutils field-list" frame="void" rules="none">
  1646. <col class="field-name" />
  1647. <col class="field-body" />
  1648. <tbody valign="top">
  1649. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  1650. <li><strong>$destroy</strong> (<em>bool</em>) – Whether to destroy session data</li>
  1651. </ul>
  1652. </td>
  1653. </tr>
  1654. <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">void</p>
  1655. </td>
  1656. </tr>
  1657. </tbody>
  1658. </table>
  1659. <p>Regenerate session ID, optionally destroying the current
  1660. session’s data.</p>
  1661. <div class="admonition note">
  1662. <p class="first admonition-title">Note</p>
  1663. <p class="last">This method is just an alias for PHP’s native
  1664. <a class="reference external" href="http://php.net/session_regenerate_id">session_regenerate_id()</a> function.</p>
  1665. </div>
  1666. </dd></dl>
  1667. <dl class="method">
  1668. <dt id="CI_Session::sess_destroy">
  1669. <code class="descname">sess_destroy</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Session::sess_destroy" title="Permalink to this definition">¶</a></dt>
  1670. <dd><table class="docutils field-list" frame="void" rules="none">
  1671. <col class="field-name" />
  1672. <col class="field-body" />
  1673. <tbody valign="top">
  1674. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">void</td>
  1675. </tr>
  1676. </tbody>
  1677. </table>
  1678. <p>Destroys the current session.</p>
  1679. <div class="admonition note">
  1680. <p class="first admonition-title">Note</p>
  1681. <p class="last">This must be the <em>last</em> session-related function
  1682. that you call. All session data will be lost after
  1683. you do that.</p>
  1684. </div>
  1685. <div class="admonition note">
  1686. <p class="first admonition-title">Note</p>
  1687. <p class="last">This method is just an alias for PHP’s native
  1688. <a class="reference external" href="http://php.net/session_destroy">session_destroy()</a> function.</p>
  1689. </div>
  1690. </dd></dl>
  1691. <dl class="method">
  1692. <dt id="CI_Session::__get">
  1693. <code class="descname">__get</code><span class="sig-paren">(</span><em>$key</em><span class="sig-paren">)</span><a class="headerlink" href="#CI_Session::__get" title="Permalink to this definition">¶</a></dt>
  1694. <dd><table class="docutils field-list" frame="void" rules="none">
  1695. <col class="field-name" />
  1696. <col class="field-body" />
  1697. <tbody valign="top">
  1698. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  1699. <li><strong>$key</strong> (<em>string</em>) – Session item key</li>
  1700. </ul>
  1701. </td>
  1702. </tr>
  1703. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The requested session data item, or NULL if it doesn’t exist</p>
  1704. </td>
  1705. </tr>
  1706. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">mixed</p>
  1707. </td>
  1708. </tr>
  1709. </tbody>
  1710. </table>
  1711. <p>A magic method that allows you to use
  1712. <code class="docutils literal"><span class="pre">$this-&gt;session-&gt;item</span></code> instead of <code class="docutils literal"><span class="pre">$_SESSION['item']</span></code>,
  1713. if that’s what you prefer.</p>
  1714. <p>It will also return the session ID by calling
  1715. <code class="docutils literal"><span class="pre">session_id()</span></code> if you try to access
  1716. <code class="docutils literal"><span class="pre">$this-&gt;session-&gt;session_id</span></code>.</p>
  1717. </dd></dl>
  1718. <dl class="method">
  1719. <dt id="CI_Session::__set">
  1720. <code class="descname">__set</code><span class="sig-paren">(</span><em>$key</em>, <em>$value</em><span class="sig-paren">)</span><a class="headerlink" href="#CI_Session::__set" title="Permalink to this definition">¶</a></dt>
  1721. <dd><table class="docutils field-list" frame="void" rules="none">
  1722. <col class="field-name" />
  1723. <col class="field-body" />
  1724. <tbody valign="top">
  1725. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  1726. <li><strong>$key</strong> (<em>string</em>) – Session item key</li>
  1727. <li><strong>$value</strong> (<em>mixed</em>) – Value to assign to the session item key</li>
  1728. </ul>
  1729. </td>
  1730. </tr>
  1731. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">void</p>
  1732. </td>
  1733. </tr>
  1734. </tbody>
  1735. </table>
  1736. <p>A magic method that allows you to assign items to
  1737. <code class="docutils literal"><span class="pre">$_SESSION</span></code> by accessing them as <code class="docutils literal"><span class="pre">$this-&gt;session</span></code>
  1738. properties:</p>
  1739. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">session</span><span class="o">-&gt;</span><span class="na">foo</span> <span class="o">=</span> <span class="s1">&#39;bar&#39;</span><span class="p">;</span>
  1740. <span class="c1">// Results in:</span>
  1741. <span class="c1">// $_SESSION[&#39;foo&#39;] = &#39;bar&#39;;</span>
  1742. </pre></div>
  1743. </div>
  1744. </dd></dl>
  1745. </dd></dl>
  1746. </div>
  1747. </div>
  1748. </div>
  1749. <footer>
  1750. <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
  1751. <a href="table.html" class="btn btn-neutral float-right" title="HTML Table Class">Next <span class="fa fa-arrow-circle-right"></span></a>
  1752. <a href="security.html" class="btn btn-neutral" title="Security Class"><span class="fa fa-arrow-circle-left"></span> Previous</a>
  1753. </div>
  1754. <hr/>
  1755. <div role="contentinfo">
  1756. <p>
  1757. &copy; Copyright 2014 - 2019, British Columbia Institute of Technology.
  1758. Last updated on Sep 19, 2019.
  1759. </p>
  1760. </div>
  1761. Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
  1762. </footer>
  1763. </div>
  1764. </div>
  1765. </section>
  1766. </div>
  1767. <script type="text/javascript">
  1768. var DOCUMENTATION_OPTIONS = {
  1769. URL_ROOT:'../',
  1770. VERSION:'3.1.11',
  1771. COLLAPSE_INDEX:false,
  1772. FILE_SUFFIX:'.html',
  1773. HAS_SOURCE: false
  1774. };
  1775. </script>
  1776. <script type="text/javascript" src="../_static/jquery.js"></script>
  1777. <script type="text/javascript" src="../_static/underscore.js"></script>
  1778. <script type="text/javascript" src="../_static/doctools.js"></script>
  1779. <script type="text/javascript" src="../_static/js/theme.js"></script>
  1780. <script type="text/javascript">
  1781. jQuery(function () {
  1782. SphinxRtdTheme.StickyNav.enable();
  1783. });
  1784. </script>
  1785. </body>
  1786. </html>