問題描述

WordPress 不使用會話。

我一直想知道當使用者從一個頁面到另一個頁面時,WP 使用什麼機制來維護使用者狀態?

最佳解決方案

它使用裸露的 cookie 並儲存登入狀態資訊客戶端。

+

=

wordpress_7339a175323c25a8547b5a6d26c49afa=yourusername%7C1457109155%7C170f103ef3dc57cdb1835662d97c1e13;

所有這些餅乾和鹽從哪裡來?

鹽在你的 wp-config.php 檔案中:

/**#@+
 * Authentication Unique Keys and Salts.
 *
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define('AUTH_KEY',         'put your unique phrase here');
define('SECURE_AUTH_KEY',  'put your unique phrase here');
define('LOGGED_IN_KEY',    'put your unique phrase here');
define('NONCE_KEY',        'put your unique phrase here');
define('AUTH_SALT',        'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',   'put your unique phrase here');
define('NONCE_SALT',       'put your unique phrase here');

獨特的短語用於 cryptographic hash function

認證 cookie,其名稱儲存在 AUTH_COOKIE 內,透過將 「wordpress_」 與 default-constants.php 中設定的 siteurl 的 md5 和連線而形成。這是預設行為,可以從配置檔案內部透過先前設定一些常量來覆蓋。

認證 cookie 是使用者名稱的連線,認證 cookie 有效的時間戳,以及 HMAC,對於那些拉 TL 的人來說,是一種 key-biased 雜湊值。三個變數與管道字串連線。

以下是 HMAC 的構建方式:

$hash = hash_hmac('md5', $username . '|' . $expiration, wp_hash($username . substr($user->user_pass, 8, 4) . '|' . $expiration, $scheme));

這是安全嗎?

根據 this article,這個答案中的大部分資訊都來自於它,如果你知道你的獨特的短語,並且如果你的金鑰是獨一無二的,那麼他們知道你的獨特的短語是 200,000,000,000,000,000,000,000,000,000,000 倍,那麼這個星期將會是一個黑社會,要求一個 30 秒的請求。

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。