Cookie.php 1.69 KB
Newer Older
Qiang Xue committed
1 2 3
<?php
/**
 * @link http://www.yiiframework.com/
Qiang Xue committed
4
 * @copyright Copyright (c) 2008 Yii Software LLC
Qiang Xue committed
5 6 7
 * @license http://www.yiiframework.com/license/
 */

Qiang Xue committed
8 9
namespace yii\web;

Qiang Xue committed
10
/**
Qiang Xue committed
11
 * Cookie represents information related with a cookie, such as [[name]], [[value]], [[domain]], etc.
Qiang Xue committed
12 13
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
Qiang Xue committed
14
 * @since 2.0
Qiang Xue committed
15
 */
Qiang Xue committed
16
class Cookie extends \yii\base\Object
Qiang Xue committed
17 18 19 20 21 22 23 24
{
	/**
	 * @var string name of the cookie
	 */
	public $name;
	/**
	 * @var string value of the cookie
	 */
Qiang Xue committed
25
	public $value = '';
Qiang Xue committed
26 27 28
	/**
	 * @var string domain of the cookie
	 */
Qiang Xue committed
29
	public $domain = '';
Qiang Xue committed
30
	/**
Qiang Xue committed
31 32
	 * @var integer the timestamp at which the cookie expires. This is the server timestamp.
	 * Defaults to 0, meaning "until the browser is closed".
Qiang Xue committed
33
	 */
Qiang Xue committed
34
	public $expire = 0;
Qiang Xue committed
35 36 37
	/**
	 * @var string the path on the server in which the cookie will be available on. The default is '/'.
	 */
Qiang Xue committed
38
	public $path = '/';
Qiang Xue committed
39 40 41
	/**
	 * @var boolean whether cookie should be sent via secure connection
	 */
Qiang Xue committed
42
	public $secure = false;
Qiang Xue committed
43 44 45
	/**
	 * @var boolean whether the cookie should be accessible only through the HTTP protocol.
	 * By setting this property to true, the cookie will not be accessible by scripting languages,
Qiang Xue committed
46
	 * such as JavaScript, which can effectively help to reduce identity theft through XSS attacks.
Qiang Xue committed
47
	 */
Qiang Xue committed
48
	public $httpOnly = false;
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

	/**
	 * Magic method to turn a cookie object into a string without having to explicitly access [[value]].
	 *
	 * ~~~
	 * if (isset($request->cookies['name'])) {
	 *     $value = (string)$request->cookies['name'];
	 * }
	 * ~~~
	 *
	 * @return string The value of the cookie. If the value property is null, an empty string will be returned.
	 */
	public function __toString()
	{
		return (string)$this->value;
	}
Qiang Xue committed
65
}