src/Cookie.php
public static function buildCookieHeader($name, $value = null, $expiryTime = 0, $path = null, $domain = null, $secureOnly = false, $httpOnly = false, $sameSiteRestriction = null) {
		if (self::isNameValid($name)) {
			$name = (string) $name;
		}
		else {
			return null;
		}

		if (self::isExpiryTimeValid($expiryTime)) {
			$expiryTime = (int) $expiryTime;
		}
		else {
			return null;
		}

		$forceShowExpiry = false;

		if (\is_null($value) || $value === false || $value === '') {
			$value = 'deleted';
			$expiryTime = 0;
			$forceShowExpiry = true;
		}

		$maxAgeStr = self::formatMaxAge($expiryTime, $forceShowExpiry);
		$expiryTimeStr = self::formatExpiryTime($expiryTime, $forceShowExpiry);

		$headerStr = self::HEADER_PREFIX . $name . '=' . \urlencode($value);

		if (!\is_null($expiryTimeStr)) {
			$headerStr .= '; expires=' . $expiryTimeStr;
		}

		// The `Max-Age` property is supported on PHP 5.5+ only (https://bugs.php.net/bug.php?id=23955).
		if (\PHP_VERSION_ID >= 50500) {
			if (!\is_null($maxAgeStr)) {
				$headerStr .= '; Max-Age=' . $maxAgeStr;
			}
		}

		if (!empty($path) || $path === 0) {
			$headerStr .= '; path=' . $path;
		}

		if (!empty($domain) || $domain === 0) {
			$headerStr .= '; domain=' . $domain;
		}

		if ($secureOnly) {
			$headerStr .= '; secure';
		}

		if ($httpOnly) {
			$headerStr .= '; httponly';
		}

		if ($sameSiteRestriction === self::SAME_SITE_RESTRICTION_LAX) {
			$headerStr .= '; SameSite=Lax';
		}
		elseif ($sameSiteRestriction === self::SAME_SITE_RESTRICTION_STRICT) {
			$headerStr .= '; SameSite=Strict';
		}

		return $headerStr;
	}
public static function buildCookieHeader($name, $value = null, $expiryTime = 0, $path = null, $domain = null, $secureOnly = false, $httpOnly = false, $sameSiteRestriction = null) {
		if (self::isNameValid($name)) {
			$name = (string) $name;
		}
		else {
			return null;
		}

		if (self::isExpiryTimeValid($expiryTime)) {
			$expiryTime = (int) $expiryTime;
		}
		else {
			return null;
		}

		$forceShowExpiry = false;

		if (\is_null($value) || $value === false || $value === '') {
			$value = 'deleted';
			$expiryTime = 0;
			$forceShowExpiry = true;
		}

		$maxAgeStr = self::formatMaxAge($expiryTime, $forceShowExpiry);
		$expiryTimeStr = self::formatExpiryTime($expiryTime, $forceShowExpiry);

		$headerStr = self::HEADER_PREFIX . $name . '=' . \urlencode($value);

		if (!\is_null($expiryTimeStr)) {
			$headerStr .= '; expires=' . $expiryTimeStr;
		}

		// The `Max-Age` property is supported on PHP 5.5+ only (https://bugs.php.net/bug.php?id=23955).
		if (\PHP_VERSION_ID >= 50500) {
			if (!\is_null($maxAgeStr)) {
				$headerStr .= '; Max-Age=' . $maxAgeStr;
			}
		}

		if (!empty($path) || $path === 0) {
			$headerStr .= '; path=' . $path;
		}

		if (!empty($domain) || $domain === 0) {
			$headerStr .= '; domain=' . $domain;
		}

		if ($secureOnly) {
			$headerStr .= '; secure';
		}

		if ($httpOnly) {
			$headerStr .= '; httponly';
		}

		if ($sameSiteRestriction === self::SAME_SITE_RESTRICTION_LAX) {
			$headerStr .= '; SameSite=Lax';
		}
		elseif ($sameSiteRestriction === self::SAME_SITE_RESTRICTION_STRICT) {
			$headerStr .= '; SameSite=Strict';
		}

		return $headerStr;
	}
public static function buildCookieHeader ( $ name , $ value = null , $ expiryTime = 0 , $ path = null , $ domain = null , $ secureOnly = false , $ httpOnly = false , $ sameSiteRestriction = null ) { if ( self :: isNameValid ( $ name ) ) { $ name = ( string ) $ name ; } else { return null ; } if ( self :: isExpiryTimeValid ( $ expiryTime ) ) { $ expiryTime = ( int ) $ expiryTime ; } else { return null ; } $ forceShowExpiry = false ; if ( \ is_null ( $ value ) || $ value === false || $ value === '' ) { $ value = 'deleted' ; $ expiryTime = 0 ; $ forceShowExpiry = true ; } $ maxAgeStr = self :: formatMaxAge ( $ expiryTime , $ forceShowExpiry ) ; $ expiryTimeStr = self :: formatExpiryTime ( $ expiryTime , $ forceShowExpiry ) ; $ headerStr = self :: HEADER_PREFIX . $ name . '=' . \ urlencode ( $ value ) ; if ( ! \ is_null ( $ expiryTimeStr ) ) { $ headerStr .= '; expires=' . $ expiryTimeStr ; } // The `Max-Age` property is supported on PHP 5.5+ only (https://bugs.php.net/bug.php?id=23955). if ( \ PHP_VERSION_ID >= 50500 ) { if ( ! \ is_null ( $ maxAgeStr ) ) { $ headerStr .= '; Max-Age=' . $ maxAgeStr ; } } if ( ! empty ( $ path ) || $ path === 0 ) { $ headerStr .= '; path=' . $ path ; } if ( ! empty ( $ domain ) || $ domain === 0 ) { $ headerStr .= '; domain=' . $ domain ; } if ( $ secureOnly ) { $ headerStr .= '; secure' ; } if ( $ httpOnly ) { $ headerStr .= '; httponly' ; } if ( $ sameSiteRestriction === self :: SAME_SITE_RESTRICTION_LAX ) { $ headerStr .= '; SameSite=Lax' ; } elseif ( $ sameSiteRestriction === self :: SAME_SITE_RESTRICTION_STRICT ) { $ headerStr .= '; SameSite=Strict' ; } return $ headerStr ; }
Builds the HTTP header that can be used to set a cookie with the specified options

@param string $name the name of the cookie which is also the key for future accesses via `$_COOKIE[...]`
@param mixed|null $value the value of the cookie that will be stored on the client's machine
@param int $expiryTime the Unix timestamp indicating the time that the cookie will expire at, i.e. usually `time() + $seconds`
@param string|null $path the path on the server that the cookie will be valid for (including all sub-directories), e.g. an empty string for the current directory or `/` for the root directory
@param string|null $domain the domain that the cookie will be valid for (including subdomains) or `null` for the current host (excluding subdomains)
@param bool $secureOnly indicates that the cookie should be sent back by the client over secure HTTPS connections only
@param bool $httpOnly indicates that the cookie should be accessible through the HTTP protocol only and not through scripting languages
@param string|null $sameSiteRestriction indicates that the cookie should not be sent along with cross-site requests (either `null`, `Lax` or `Strict`)
@return string the HTTP header
Builds the HTTP header that can be used to set a cookie with the specified options