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