forked from NEKOGET/FuelPHP_docs_jp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcookie.html
300 lines (285 loc) · 10.5 KB
/
cookie.html
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
<!doctype html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./../assets/css/combined.css">
<link rel="shortcut icon" href="./../favicon.ico" />
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
var path = './../';
var class_prefix = "Cookie::";
</script>
<script src="./../assets/js/combined.js"></script>
<title>Cookie - クラス - FuelPHP ドキュメント</title>
</head>
<body>
<div id="container">
<header id="header">
<div class="table">
<h1>
<a href="http://fuelphp.com"><img height="37px" width="147px" src="./../assets/img/fuel.png" /></a>
<strong>Documentation</strong>
</h1>
<form id="google_search">
<p>
<span id="search_clear"> </span>
<input type="submit" name="search_submit" id="search_submit" value="検索" />
<input type="text" value="" id="search_input" name="search_input" />
</p>
</form>
</div>
<nav>
<div class="clear"></div>
</nav>
<a href="#" id="toc_handle">目次</a>
<div class="clear"></div>
</header>
<div id="cse">
<div id="cse_point"></div>
<div id="cse_content"></div>
</div>
<div id="main">
<h2>Cookie クラス</h2>
<p>cookie クラスは cookie の値の取得、設定、削除を行うことができます。</p>
<h3 id="configuration">設定</h3>
<p>cookie クラスの設定はアプリケーションの共通設定ファイル <strong>app/config/config.php</strong> で行います。設定項目は '<strong>cookie</strong>' セクションの中にあり、次のように設定されています。</p>
<table class="method">
<tbody>
<tr>
<th>パラメータ</th>
<th>型</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>expiration</kbd></th>
<td>integer</td>
<td><pre class="php"><code>0</code></pre></td>
<td>cookie の有効期限。この値は set() 関数で $expiration が指定されていないときに使われます。</td>
</tr>
<tr>
<th><kbd>path</kbd></th>
<td>string</td>
<td><pre class="php"><code>'/'</code></pre></td>
<td>cookie が有効となるパスを制限します。この値は set() 関数で $path が指定されていないときに使われます。</td>
</tr>
<tr>
<th><kbd>domain</kbd></th>
<td>string</td>
<td><pre class="php"><code>null</code></pre></td>
<td>cookie が有効となるドメインを制限します。この値は set() 関数で $domain が指定されていないときに使われます。</td>
</tr>
<tr>
<th><kbd>secure</kbd></th>
<td>boolean</td>
<td><pre class="php"><code>false</code></pre></td>
<td>true を設定したときはセキュアな接続の時のみ cookie が送信されます。</td>
</tr>
<tr>
<th><kbd>httponly</kbd></th>
<td>boolean</td>
<td><pre class="php"><code>false</code></pre></td>
<td>true を設定したときは HTTP によるアクセスのときのみ cookie が送信されます。 Javascript によるアクセスの時は送信されません。</td>
</tr>
</tbody>
</table>
<p>もしこれらのうち1つあるいは複数の値が設定から抜けていた場合、Cookie クラスは表に定義されているデフォルトの値が適用されます。</p>
<p class="note">
クッキーを利用する場合、<em>app/config/config.php</em> 及び <em>php.ini</em> の設定が
サーバのタイムゾーンと合っていることを必ず確認して下さい。
クッキーの有効期限のタイムスタンプはグリニッジ標準時なので、タイムゾーンにずれがあると有効期限が誤って計算され、
正しく有効期限切れにならなかったり、ブラウザが既に有効期限切れになってしまいクッキーが全く効かなくなってしまいます。
</p>
<article>
<h4 class="method" id="method_get">get($name = null, $default = null)</h4>
<p><strong>get</strong> 関数は $_COOKIE 変数から値を取得します。$name が指定されていないときは全ての値を取得します。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>はい</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$name</kbd></th>
<td><i>任意</i></td>
<td>$_COOKIE 変数の中でのキー</td>
</tr>
<tr>
<th><kbd>$default</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>指定された $name が取得できなかったときに返すデフォルトの値</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>mixed</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>$theme = Cookie::get('theme', 'blue');</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_set">set($name, $value, $expiration = null, $path = null, $domain = null, $secure = null, $httponly = null)</h4>
<p><strong>set</strong> 関数は cookie を作成し、値を設定します。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>はい</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$name</kbd></th>
<td><i>必須</i></td>
<td>$_COOKIE 変数内でのキー</td>
</tr>
<tr>
<th><kbd>$value</kbd></th>
<td><i>必須</i></td>
<td>cookie に設定する値</td>
</tr>
<tr>
<th><kbd>$expiration</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>cookie の有効期間(秒)</td>
</tr>
<tr>
<th><kbd>$path</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>cookie が有効となるパス</td>
</tr>
<tr>
<th><kbd>$domain</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>cookie が有効となるドメイン</td>
</tr>
<tr>
<th><kbd>$secure</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>true を設定したときはセキュアな接続の時のみ cookie が送信されます。</td>
</tr>
<tr>
<th><kbd>$httponly</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>true を設定したときは HTTP によるアクセスのときのみ cookie が送信されます。 Javascript によるアクセスの時は送信されません。</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>boolean</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>Cookie::set('theme', 'blue', 60 * 60 * 24);</code></pre>
</td>
</tr>
</tbody>
</table>
<p>デフォルトが <strong>null</strong> のパラメータについては、 <strong>null</strong> 、もしくは未指定の場合は共通設定ファイルで指定された設定値が使われます。</p>
</article>
<article>
<h4 class="method" id="method_delete">delete($name, $path = null, $domain = null, $secure = null, $httponly = null)</h4>
<p><strong>delete</strong> 関数は $_COOKIE 変数から値を削除します。</p>
<p class="note">
クッキーが特定のパスあるいはドメインにおいて生成された時、delete 関数も与えておく必要があります。
</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>はい</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$name</kbd></th>
<td><i>必須</i></td>
<td>削除するキー</td>
</tr>
<tr>
<th><kbd>$path</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>cookie が有効となるパス</td>
</tr>
<tr>
<th><kbd>$domain</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>cookie が有効となるドメイン</td>
</tr>
<tr>
<th><kbd>$secure</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>true を設定したときはセキュアな接続の時のみ cookie が送信されます。</td>
</tr>
<tr>
<th><kbd>$httponly</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>true を設定したときは HTTP によるアクセスのときのみ cookie が送信されます。 Javascript によるアクセスの時は送信されません。</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>void</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// 通常のクッキーを削除する
\Cookie::delete('theme');
// パスとともにクッキーを設定する
\Cookie::set('theme', 'fuel', null, '/account/');
// パスで設定したクッキーを削除する
\Cookie::delete('theme', '/account/');
</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
</div>
<footer>
<p>
© FuelPHP Development Team 2010-2016 - <a href="http://fuelphp.com">FuelPHP</a> is released under the MIT license.
[ <a href="https://github.com/fuel/docs/commits/1.8/develop/classes/cookie.html">原文コミット履歴</a> | <a href="https://github.com/NEKOGET/FuelPHP_docs_jp/commits/1.8/develop_japanese/classes/cookie.html">翻訳コミット履歴</a> | <a href="https://github.com/NEKOGET/FuelPHP_docs_jp/blob/1.8/develop_japanese/classes/cookie.html">GitHubで修正</a> ]
</p>
</footer>
</div>
</body>
</html>