Secure cookie flags help keep session cookies on HTTPS and less reachable from JavaScript. That reduces some XSS and cookie-theft paths. Your site must already work over HTTPS.
One-click fix (Pro)
- Go to Security Ninja → Fixes.
- Enable Secure Cookies.
- Security Ninja writes the matching
@ini_setlines intowp-config.php.
Manual setup
Add these lines to wp-config.php above the “That’s all, stop editing!” line:
@ini_set( 'session.cookie_httponly', true );
@ini_set( 'session.cookie_secure', true );
@ini_set( 'session.use_only_cookies', true );
What the three lines do
session.cookie_httponly: the session cookie can’t be read by JavaScript, so a malicious script injected into a page can’t steal it.session.cookie_secure: the browser only sends the session cookie over HTTPS, never over plain HTTP.session.use_only_cookies: PHP won’t accept a session ID in the URL (for example?PHPSESSID=...), which stops session IDs leaking through links and logs.
These settings apply to PHP sessions. WordPress itself doesn’t always use PHP sessions; they’re mainly started by some plugins and themes (shops, forms, membership plugins). The fix makes sure those session cookies are protected if and when one is created.
How to check it works
- Confirm the fix shows as enabled under Security Ninja → Fixes (Pro), or that the three lines are in
wp-config.phpabove “That’s all, stop editing!”. - Open your site over
https://(check the padlock in the address bar). - Clear cookies for your site, then log in to WordPress again.
- Open developer tools: right-click the page and choose Inspect, or press F12 (Mac: Cmd+Option+I).
- Chrome/Edge: open the Application tab, then Storage > Cookies in the left sidebar, then click your site’s address. Firefox: Storage tab, then Cookies. Safari: enable the Develop menu first (Settings > Advanced), then Develop > Show Web Inspector > Storage > Cookies.
- Look at the HttpOnly and Secure columns. A tick (✓) means the flag is set.
- What you should see:
PHPSESSID(if present): ticks in both HttpOnly and Secure. This is the cookie the fix controls.wordpress_sec_*andwordpress_logged_in_*: WordPress sets these when you log in. On an HTTPS site they should also show HttpOnly and Secure. They’re a good sanity check that your login cookies are protected, but they’re controlled by WordPress core, not by these three lines.
No PHPSESSID in the list? That’s normal. It only appears when a plugin or theme starts a PHP session. Nothing is broken, and the fix will apply as soon as one is created.
Not working? Check these
- Still seeing HTTP: the site must load over HTTPS everywhere. Check Settings > General (WordPress Address and Site Address both start with
https://) and that HTTP redirects to HTTPS. Withsession.cookie_secureon, sessions won’t work over plain HTTP. - Caching: clear the site cache, any host or CDN cache (for example Cloudflare), and browser cookies, then log in again.
- Lines missing: if
wp-config.phpisn’t writable, the one-click fix can’t add the lines. Add them manually as shown above, or ask your host. - Host overrides: some hosts block
ini_setor set session options in their own PHP config. IfPHPSESSIDexists but lacks the flags, ask your host to setsession.cookie_httponly = 1,session.cookie_secure = 1andsession.use_only_cookies = 1in PHP settings (php.ini/.user.ini). - Still stuck: email [email protected] with a screenshot of the cookie list.
Related: Fixes overview.
