38 $this->
set(
$value, $attr );
53 public function set(
$value, $attr ) {
56 if ( isset( $attr[
'expires'] ) ) {
57 $this->isSessionKey =
false;
58 $this->expires = strtotime( $attr[
'expires'] );
61 $this->path = $attr[
'path'] ??
'/';
63 if ( isset( $attr[
'domain'] ) ) {
64 if ( self::validateCookieDomain( $attr[
'domain'] ) ) {
65 $this->domain = $attr[
'domain'];
68 throw new InvalidArgumentException(
'$attr must contain a domain' );
92 if ( substr(
$domain, -1 ) ==
'.' ||
94 count( $dc ) == 2 && $dc[0] ===
''
100 if ( preg_match(
'/^[0-9.]+$/',
$domain ) ) {
101 if ( count( $dc ) !== 4 || ip2long(
$domain ) ===
false ) {
105 if ( $originDomain ==
null || $originDomain ==
$domain ) {
112 if ( ( count( $dc ) == 2 && strlen( $dc[0] ) <= 2 )
113 || ( count( $dc ) == 3 && strlen( $dc[0] ) == 0 && strlen( $dc[1] ) <= 2 ) ) {
116 if ( ( count( $dc ) == 2 || ( count( $dc ) == 3 && $dc[0] ==
'' ) )
117 && preg_match(
'/(com|net|org|gov|edu)\...$/',
$domain ) ) {
122 if ( $originDomain !=
null ) {
123 if ( substr(
$domain, 0, 1 ) !=
'.' &&
$domain != $originDomain ) {
127 if ( substr(
$domain, 0, 1 ) ==
'.'
168 || ( strlen(
$domain ) > strlen( $this->domain )
169 && str_starts_with( $this->domain,
'.' )
173 -strlen( $this->domain ),
174 strlen( $this->domain ),
190 return ( $this->path && substr_compare( $this->path,
$path, 0, strlen( $this->path ) ) == 0 );
197 return $this->isSessionKey || $this->expires > time();
serializeToHttpRequest( $path, $domain)
Serialize the cookie jar into a format useful for HTTP Request headers.
__construct( $name, $value, $attr)
static validateCookieDomain( $domain, $originDomain=null)
Return the true if the cookie is valid is valid.