WC_Session_Handler::get_session_cookie()publicWC 1.0

Get the session cookie, if set. Otherwise return false.

Session cookies without a customer ID are invalid.

Метод класса: WC_Session_Handler{}

Хуков нет.

Возвращает

true|false|Массив.

Использование

$WC_Session_Handler = new WC_Session_Handler();
$WC_Session_Handler->get_session_cookie();

Код WC_Session_Handler::get_session_cookie() WC 8.7.0

public function get_session_cookie() {
	$cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine.

	if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) {
		return false;
	}

	$parsed_cookie = explode( '||', $cookie_value );

	if ( count( $parsed_cookie ) < 4 ) {
		return false;
	}

	list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = $parsed_cookie;

	if ( empty( $customer_id ) ) {
		return false;
	}

	// Validate hash.
	$to_hash = $customer_id . '|' . $session_expiration;
	$hash    = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );

	if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) {
		return false;
	}

	return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash );
}