wp_parse_auth_cookie

Parse a cookie into its components.

Description

(array|false) wp_parse_auth_cookie( (string) $cookie = '', (string) $scheme = '' ); 

Returns (array|false)

Authentication cookie components

Parameters (2)

0. $cookie — Optional. (string) => ''
The cookie.
1. $scheme — Optional. (string) => ''
The cookie scheme to use: auth, secure_auth, or logged_in

Usage

  1. if ( !function_exists( 'wp_parse_auth_cookie' ) ) { 
  2. require_once ABSPATH . WPINC . '/pluggable.php'; 
  3.  
  4. // The cookie. 
  5. $cookie = ''; 
  6.  
  7. // Optional. The cookie scheme to use: auth, secure_auth, or logged_in 
  8. $scheme = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wp_parse_auth_cookie($cookie, $scheme); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/pluggable.php  
  1. function wp_parse_auth_cookie($cookie = '', $scheme = '') { 
  2. if ( empty($cookie) ) { 
  3. switch ($scheme) { 
  4. case 'auth': 
  5. $cookie_name = AUTH_COOKIE
  6. break; 
  7. case 'secure_auth': 
  8. $cookie_name = SECURE_AUTH_COOKIE
  9. break; 
  10. case "logged_in": 
  11. $cookie_name = LOGGED_IN_COOKIE
  12. break; 
  13. default: 
  14. if ( is_ssl() ) { 
  15. $cookie_name = SECURE_AUTH_COOKIE
  16. $scheme = 'secure_auth'; 
  17. } else { 
  18. $cookie_name = AUTH_COOKIE
  19. $scheme = 'auth'; 
  20.  
  21. if ( empty($_COOKIE[$cookie_name]) ) 
  22. return false; 
  23. $cookie = $_COOKIE[$cookie_name]; 
  24.  
  25. $cookie_elements = explode('|', $cookie); 
  26. if ( count( $cookie_elements ) !== 4 ) { 
  27. return false; 
  28.  
  29. list( $username, $expiration, $token, $hmac ) = $cookie_elements; 
  30.  
  31. return compact( 'username', 'expiration', 'token', 'hmac', 'scheme' );