File tree Expand file tree Collapse file tree 2 files changed +4
-3
lines changed
Expand file tree Collapse file tree 2 files changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -87,14 +87,15 @@ final class Cookie
8787 *
8888 * @param string $name The name of the cookie which is also the key for
8989 * future accesses via `$_COOKIE[...]`.
90+ * @param string $domain The domain that the cookie will be valid for (including all subdomains)
9091 */
91- public function __construct (string $ name )
92+ public function __construct (string $ name, string $ domain = null )
9293 {
9394 $ this ->name = $ name ;
9495 $ this ->value = null ;
9596 $ this ->expiryTime = 0 ;
9697 $ this ->path = '/ ' ;
97- $ this ->domain = self ::normalizeDomain ($ _SERVER ['HTTP_HOST ' ]);
98+ $ this ->setDomain ( self ::normalizeDomain ($ domain ?? $ _SERVER ['HTTP_HOST ' ]));
9899 $ this ->httpOnly = true ;
99100 $ this ->secureOnly = false ;
100101 $ this ->sameSiteRestriction = self ::SAME_SITE_RESTRICTION_STRICT ;
Original file line number Diff line number Diff line change 106106testEqual ((new \ParagonIE \Cookie \Cookie ('key ' ))->setValue ('value ' )->setDomain ('.localhost ' ), 'Set-Cookie: key=value; path=/; httponly; SameSite=Lax ' );
107107testEqual ((new \ParagonIE \Cookie \Cookie ('key ' ))->setValue ('value ' )->setDomain ('127.0.0.1 ' ), 'Set-Cookie: key=value; path=/; httponly; SameSite=Lax ' );
108108testEqual ((new \ParagonIE \Cookie \Cookie ('key ' ))->setValue ('value ' )->setDomain ('.local ' ), 'Set-Cookie: key=value; path=/; httponly; SameSite=Lax ' );
109- testEqual ((new \ParagonIE \Cookie \Cookie ('key ' ))->setValue ('value ' )-> setDomain ( ' example.com ' ), 'Set-Cookie: key=value; path=/; domain=.example.com; httponly; SameSite=Lax ' );
109+ testEqual ((new \ParagonIE \Cookie \Cookie ('key ' , ' example.com ' ))->setValue ('value ' ), 'Set-Cookie: key=value; path=/; domain=.example.com; httponly; SameSite=Lax ' );
110110testEqual ((new \ParagonIE \Cookie \Cookie ('key ' ))->setValue ('value ' )->setDomain ('.example.com ' ), 'Set-Cookie: key=value; path=/; domain=.example.com; httponly; SameSite=Lax ' );
111111testEqual ((new \ParagonIE \Cookie \Cookie ('key ' ))->setValue ('value ' )->setDomain ('www.example.com ' ), 'Set-Cookie: key=value; path=/; domain=.example.com; httponly; SameSite=Lax ' );
112112testEqual ((new \ParagonIE \Cookie \Cookie ('key ' ))->setValue ('value ' )->setDomain ('.www.example.com ' ), 'Set-Cookie: key=value; path=/; domain=.example.com; httponly; SameSite=Lax ' );
You can’t perform that action at this time.
0 commit comments