blob: 9c17cdd5c70179e29e58bde515aa33d801f2b6cc [file] [log] [blame]
adminb0dd10f2006-08-25 17:25:49 +00001<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html>
3<head>
4
5<title>Code Igniter User Guide</title>
6
7<style type='text/css' media='all'>@import url('../userguide.css');</style>
8<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
9
10<script type="text/javascript" src="../scripts/nav.js"></script>
11<script type="text/javascript" src="../scripts/prototype.lite.js"></script>
12<script type="text/javascript" src="../scripts/moo.fx.js"></script>
13<script type="text/javascript">
14window.onload = function() {
15 myHeight = new fx.Height('nav', {duration: 400});
16 myHeight.hide();
17}
18</script>
19
20<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
21<meta http-equiv='expires' content='-1' />
22<meta http-equiv= 'pragma' content='no-cache' />
23<meta name='robots' content='all' />
24<meta name='author' content='Rick Ellis' />
25<meta name='description' content='Code Igniter User Guide' />
26
27</head>
28<body>
29
30<!-- START NAVIGATION -->
31<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
32<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle.jpg" width="153" height="44" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
33<div id="masthead">
34<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
35<tr>
admin9fc347d2006-09-21 00:00:28 +000036<td><h1>Code Igniter User Guide Version 1.4.1</h1></td>
adminb0dd10f2006-08-25 17:25:49 +000037<td id="breadcrumb_right"><a href="../toc.html">Full Table of Contents</a></td>
38</tr>
39</table>
40</div>
41<!-- END NAVIGATION -->
42
43
44<!-- START BREADCRUMB -->
45<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
46<tr>
47<td id="breadcrumb">
48<a href="http://www.codeigniter.com/">Code Igniter Home</a> &nbsp;&#8250;&nbsp;
49<a href="../index.html">User Guide Home</a> &nbsp;&#8250;&nbsp;
50Cookie Helper
51</td>
52<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="www.codeigniter.com/user_guide/" />Search User Guide&nbsp; <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" />&nbsp;<input type="submit" class="submit" name="sa" value="Go" /></form></td>
53</tr>
54</table>
55<!-- END BREADCRUMB -->
56
57<br clear="all" />
58
59
60<!-- START CONTENT -->
61<div id="content">
62
63
64<h1>Cookie Helper</h1>
65
66<p>The Cookie Helper file contains functions that assist in working with cookies.</p>
67
68
69<h2>Loading this Helper</h2>
70
71<p>This helper is loaded using the following code:</p>
72<code>$this->load->helper('cookie');</code>
73
74<p>The following functions are available:</p>
75
76<h2>set_cookie()</h2>
77
78<p>Sets a cookie containing the values you specify. There are two ways to pass information this function so that a cookie can be set:
admin885b0342006-09-21 05:36:15 +000079Array Method, and Discreet Parameters:</p>
adminb0dd10f2006-08-25 17:25:49 +000080
81<h4>Array Method</h4>
82
83<p>Using this method, an associative array is passed to the first parameter:</p>
84
85<code>$cookie = array(<br />
86&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'name'&nbsp;&nbsp;&nbsp;=> 'The Cookie Name',<br />
87&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'value'&nbsp;&nbsp;=> 'The Value',<br />
88&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'expire' => '86500',<br />
89&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'domain' => '.some-domain.com',<br />
90&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'path'&nbsp;&nbsp;&nbsp;=> '/',<br />
91&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'prefix' => 'myprefix_',<br />
92&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br />
93<br />
94set_cookie($cookie);
95</code>
96
97<p><strong>Notes:</strong></p>
98
99<p>Only the name and value are required.</p>
100
101<p>The expiration is set in <strong>seconds</strong>, which will be added to the current time. Do not include the time, but rather only the
102number of seconds from <em>now</em> that you wish the cookie to be valid. If the expiration is set to
103zero the cookie will only last as long as the browser is open.</p>
104<p>To delete a cookie set it with the expiration blank.</p>
105<p>For site-wide cookies regardless of how your site is requested, add your URL to the <strong>domain</strong> starting with a period, like this: .your-domain.com</p>
106<p>The path is usually not needed since the function sets a root path.</p>
107<p>The prefix is only needed if you need to avoid name collisions with other identically named cookies for your server.</p>
108
109<h4>Discreet Parameters</h4>
110
111<p>If you prefer, you can set the cookie by passing data using individual parameters:</p>
112
113<code>set_cookie($name, $value, $expire, $domain, $path, $prefix);</code>
114
admin885b0342006-09-21 05:36:15 +0000115<h2>get_cookie()</h2>
116
117<p>Lets you fetch a cookie. The first parameter will contain the name of the cookie you are looking for:</p>
118
119<code>get_cookie('some_cookie');</code>
120
121<p>The function returns FALSE (boolean) if the item you are attempting to retrieve does not exist.</p>
122
123<p>The second optional parameter lets you run the data through the XSS filter. It's enabled by setting the second parameter to boolean TRUE;</p>
124
125<code>get_cookie('some_cookie', TRUE);</code>
126
127
128
129<h2>delete_cookie()</h2>
130
131<p>Lets you delete a cookie. Unless you've set a custom path or other values, only the name of the cookie is needed:</p>
132
133<code>delete_cookie("name");</code>
134
135<p>This function is otherwise identical to <dfn>set_cookie()</dfn>, except that it does not have the value and expiration parameters. You can submit an array
136of values in the first parameter or you can set discreet parameters.</p>
137
138<code>delete_cookie($name, $domain, $path, $prefix)</code>
adminb0dd10f2006-08-25 17:25:49 +0000139
140
141</div>
142<!-- END CONTENT -->
143
144
145<div id="footer">
146<p>
147Previous Topic:&nbsp;&nbsp;<a href="array_helper.html">Array Helper</a>
148&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
149<a href="#top">Top of Page</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
150<a href="../index.html">User Guide Home</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
151Next Topic:&nbsp;&nbsp;<a href="date_helper.html">Date Helper</a>
152<p>
153<p><a href="http://www.codeigniter.com">Code Igniter</a> &nbsp;&middot;&nbsp; Copyright &#169; 2006 &nbsp;&middot;&nbsp; <a href="http://www.pmachine.com">pMachine, Inc.</a></p>
154</div>
155
156</body>
157</html>