Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

WordPress normally keeps users signed in with authentication cookies, not PHP sessions. The browser stores a cookie value and sends it with matching requests; WordPress verifies that value to identify the user. A PHP session keeps the actual state on the server and gives the browser only a session identifier. For ordinary WordPress login, use the built-in cookie system. Add a custom PHP session only when your plugin genuinely needs temporary, server-side state that WordPress authentication does not provide.

What WordPress cookies do

A cookie is a small value stored by the browser and attached automatically to requests that match its domain, path, security and same-site rules. WordPress uses cookies to verify identity, maintain login state and remember selected preferences. The value is held on the client, so anyone who obtains a valid authentication cookie may be able to replay it as the user until it expires or the server invalidates it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

WordPress authentication cookies are created by the normal login flow. The principal cookies are:

Cookie Typical scope Purpose
wordpress_[hash] Administration area Authenticates access to the WordPress dashboard.
wordpress_logged_in_[hash] Front end Lets WordPress recognize a logged-in visitor outside the dashboard.
wordpress_sec_[hash] Secure HTTPS login Used for authentication when secure login cookies are enabled.
Settings cookies Administration and user preferences Remember interface choices and other customization settings.
Comment cookies Comment forms Remember details a commenter has entered so they do not need to retype them.
Language cookies Localized interfaces Remember a language or locale selection where the installation supports it.
Test cookies Capability checks Help WordPress determine whether the browser accepts cookies.

The exact hash in an authentication-cookie name varies by site configuration. Do not write plugin logic that assumes one fixed hash or that treats a cookie name alone as proof of identity; WordPress must validate the complete value.

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application: attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Economical &Reusable: Built durable materials with a long-lasting battery,our CAGIWIRU air duster it's a sustainable alternative to disposable air cans.

Cookies and PHP sessions: the fundamental difference

Both mechanisms can maintain state across requests, but they place that state in different locations and have different operational consequences.

Concern WordPress authentication cookie Custom PHP session
Where state lives The browser holds an authentication value that WordPress validates. The server holds session data; the browser normally holds only an identifier.
Framework integration Built into WordPress login, user APIs, capabilities and nonce handling. Must be started, read and ended by your plugin or application code.
Lifetime Uses WordPress authentication expiration rules, including the Remember Me choice. You define idle and absolute expiration and any renewal policy.
Invalidation WordPress can invalidate authentication on logout and other account events. Your server-side store must remove or revoke the session record.
CSRF protection State-changing REST requests made with cookie authentication require a WordPress REST nonce. You must add an appropriate CSRF defense to every state-changing endpoint that relies on the session cookie.
Caching Responses that vary by login cookie must not be served from an unauthenticated full-page cache. Session-dependent pages have the same cache problem and can create more cache variation.
Horizontal scaling WordPress can validate its authentication cookies on multiple web servers when they share the relevant site configuration. Multiple servers need a shared session store or carefully managed affinity; local file sessions alone can fail when requests move between servers.
If a bearer value is stolen An attacker may use the cookie until it expires or is invalidated. An attacker may use the session identifier until the server-side session expires or is revoked.

A PHP session is not automatically more secure than a WordPress cookie. Keeping sensitive state on the server limits what is exposed in the browser, but the identifier remains a bearer credential. Strong transport security, cookie attributes, rotation and server-side invalidation are required either way.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How long WordPress login cookies last

Under the default WordPress authentication settings documented for current login guidance, a normal login cookie expires after two days, or 48 hours. Selecting Remember Me makes the cookie persistent for 14 days. These are default durations, not a promise that every site uses those exact values: administrators, plugins or hosting policy may change authentication behavior.

Login choice Default persistence What the browser does
Remember Me not selected Two days (48 hours) WordPress creates a browser-session authentication cookie subject to the normal two-day authentication expiration.
Remember Me selected Fourteen days WordPress creates a persistent cookie intended to survive closing and reopening the browser.

Expiration is only one control. A server can invalidate a credential before its scheduled expiry, and a user can lose the cookie by clearing browser data or changing browser profiles. Conversely, deleting a cookie in one browser does not revoke a copied value held elsewhere.

Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth

Use the supported WordPress API for authentication

When a plugin needs to sign a user in, use the documented function rather than constructing authentication cookies yourself:

wp_set_auth_cookie( $user_id, $remember, $secure );

$user_id identifies the account. $remember is a Boolean corresponding to the persistent Remember Me behavior. $secure indicates whether the cookie should be restricted to secure HTTPS transport. Let WordPress create and validate the complete set of authentication cookies so that core login, logout, capability checks and nonce verification remain consistent.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The older wp_setcookie() API has been deprecated since WordPress 2.5.0. New code should not call it or imitate its historical behavior. If a login form, single-sign-on bridge or custom endpoint needs to authenticate a user, complete the user validation first, then call the supported authentication API and redirect only after the cookies have been sent successfully.

Secure cookie and session design

Authentication state should be treated as a credential, not as harmless preference data. Apply these controls to WordPress cookies and to any custom session identifier:

Rank #3
Sale
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black | LED mouse pad with 14 lighting modes, covers keyboard & mouse, anti-slip rubber base, waterproof surface, USB powered
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.
  • Use HTTPS for the entire authenticated flow. Do not allow a login or authenticated request to fall back to cleartext HTTP. Set the Secure attribute so the browser sends the identifier only over HTTPS.
  • Set HttpOnly when JavaScript does not need the value. This prevents ordinary page scripts from reading the identifier and reduces the impact of script-based theft. It does not stop an attacker from using a value already stolen by another route.
  • Choose an appropriate SameSite policy. Lax is a practical default for many sites and Strict is more restrictive when the user experience permits it. SameSite is defense in depth, not a replacement for CSRF tokens.
  • Regenerate identifiers after authentication and privilege changes. Rotation limits session-fixation attacks in which an attacker tries to make a victim use an identifier known to the attacker.
  • Keep secrets out of unsigned client cookies. Do not store passwords, API keys, authorization decisions or sensitive personal data directly in a value that the client can read or replay. Store sensitive state server-side, or use a well-designed integrity-protected token with a narrowly defined purpose.
  • Invalidate on logout and high-risk events. Remove or revoke the server-side session and rotate relevant authentication state after password changes, account recovery, suspected theft or privilege changes. Clearing a browser cookie alone cannot invalidate a copied identifier.
  • Protect cookie scope. Use the narrowest practical domain and path, and avoid making a sensitive cookie available to unrelated applications on the same host.

When a custom PHP session is justified

WordPress authentication already answers the question “which user is this?” A custom session is useful when a plugin needs temporary server-side state that is not an account identity: for example, a multi-step workflow, a short-lived checkout draft, a rate-limit record or a wizard that must survive several requests without placing its contents in the browser.

Do not call session_start() casually in a theme or plugin. Starting a session after output has begun can fail to send headers, and starting one on every request can interfere with full-page caching and create unnecessary state. First decide whether a user meta field, a transient, a signed one-time token or another WordPress-native mechanism meets the requirement with less complexity.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If a PHP session is genuinely required, use an explicit lifecycle:

  1. Start before output. Initialize the session at a predictable early hook or entry point, before WordPress or the theme sends any response body. Coordinate this with the hosting stack and any reverse proxy.
  2. Configure the session cookie. Set Secure, HttpOnly and an appropriate SameSite value. Give the cookie a narrow path and avoid exposing it to applications that do not need it.
  3. Use a server-side store. Keep the actual workflow or account-related state on the server. On more than one web server, use a shared session backend or another design that guarantees every request can find the same record.
  4. Rotate the identifier. Regenerate it immediately after login, elevation of privileges or any transition where an anonymous workflow becomes associated with an account.
  5. Define expiration. Choose idle and absolute limits appropriate to the data, and remove abandoned records so the store does not grow indefinitely.
  6. Validate every read. Check ownership, expected state transitions, expiration and authorization on the server. A session identifier proves possession, not permission to perform every operation.
  7. Destroy on logout or revocation. Delete the server-side record and expire the browser cookie. Repeat the invalidation after password changes or other high-risk events.

A minimal conceptual flow looks like this:

start_session_before_output();
rotate_identifier_after_login();
$_SESSION['workflow_id'] = $server_side_record_id;
validate_owner_and_expiration($_SESSION['workflow_id']);
remove_server_side_record_on_logout();
expire_session_cookie_on_logout();

The function names in this example describe responsibilities rather than a drop-in WordPress API. Implement them with the session and storage facilities appropriate to your hosting environment, and test behavior through your cache, proxy and load-balancer layers.

Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why the WordPress REST API needs a nonce when you are logged in

Cookie authentication happens automatically during the ordinary WordPress login flow. A browser then attaches the login cookie to matching REST requests. Because another site could try to make that browser send a request, WordPress requires a REST nonce for cookie-authenticated REST operations. The nonce is commonly sent in the X-WP-Nonce header or as the _wpnonce parameter.

A request with a login cookie but without a valid REST nonce is treated as unauthenticated for this purpose. The nonce proves that the request came through a page or script that received the site’s expected anti-CSRF value; it does not grant capabilities and does not replace authorization checks.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Client code typically reads a nonce supplied to the page by WordPress and sends it with a state-changing request:

fetch('/wp-json/example/v1/item', {
  method: 'POST',
  headers: {
    'X-WP-Nonce': wpApiSettings.nonce,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ title: 'Example' })
});

The endpoint must still verify the current user’s capabilities, validate and sanitize input, enforce object ownership where applicable, and return an appropriate error when authorization fails. A nonce is a CSRF defense, not an alternative login token and not a reason to skip current_user_can() or equivalent checks.

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.

Cookies, sessions and page caching

Full-page caches work best when the same response can be served to many visitors. A response that changes according to a login or session cookie cannot safely be reused for everyone. Exclude login pages, authenticated pages and cookie-varying responses from public caching; WordPress login guidance specifically calls out wp-login.php and cookie-based sessions when configuring server caches.

Common symptoms of a cache mistake include a logged-in user seeing a logged-out page, one user seeing another user’s personalized response, a login redirect loop, or a REST request receiving stale data. Purge the affected cache, inspect cache-control and vary rules, and verify that the cache key distinguishes every cookie that changes the response. Do not “fix” a privacy problem by exposing more cookie contents to JavaScript.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choosing the right mechanism

Need Prefer Reason
Identify a WordPress user across normal page loads WordPress authentication cookies They integrate with core login, capabilities, logout and REST nonce checks.
Remember a non-sensitive display preference A narrowly scoped preference cookie The browser can supply the value without creating server-side session state.
Hold sensitive, temporary, multi-request state A server-side session or WordPress-native server-side store The browser carries only an identifier, while the data remains under server control.
Authenticate an API request from a logged-in browser WordPress cookie authentication plus a REST nonce The cookie identifies the session and the nonce mitigates CSRF; capability checks remain mandatory.
Share state across several web servers WordPress’s normal authentication or a shared session backend Local-only session files can disappear when the next request reaches another server.

Troubleshooting checklist

  • The user is logged in but appears logged out: check HTTPS consistency, the cookie domain and path, clock or expiry issues, cache exclusions and whether a proxy is rewriting secure headers.
  • A custom session is empty on the next request: confirm that the session started before output, that the browser accepted the cookie, that the identifier is returned on the next request and that every server can reach the same session store.
  • REST returns an authentication or nonce error: send the current nonce in X-WP-Nonce or _wpnonce, ensure the request includes the browser’s login cookie, and check that the page has not been cached with an outdated nonce.
  • Logout did not stop a suspicious request: revoke the server-side session or authentication state as well as deleting the local browser cookie, then rotate credentials after the security event.
  • Headers-already-sent warnings appear: find output emitted before cookie or session initialization, including whitespace, debug messages and template output. Move initialization earlier and keep session startup out of requests that do not need it.

Bottom line

Use WordPress authentication cookies for WordPress identity: they are the supported, integrated mechanism, with a default two-day authentication expiration and a 14-day Remember Me persistence. Use PHP sessions only for a specific server-side state requirement, and then design the complete lifecycle—HTTPS, secure cookie attributes, identifier rotation, expiration, shared storage, CSRF protection, cache exclusions and server-side invalidation. A cookie or session identifier is a bearer credential, so possession must never be treated as proof that every requested action is authorized.