Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change PHPSESSID cookie domain name in Wordpress?

I have a WordPress site which sets the PHPSESSID cookie with domain name www.example.com.

I want it to set it to .example.com so I can use it in the subdomain.

like image 407
Siddharth Doshi Avatar asked Mar 10 '19 11:03

Siddharth Doshi


1 Answers

Set the domain calling session_set_cookie_params().

Read the docs here.

Basically do something like:

 session_set_cookie_params ( 0, '/', 'example.com' );

If you are on PHP 7.3 you can do it like this:

session_set_cookie_params ( ['domain' => 'example.com'] );

Call this early in execution. Setting this on your wp-config.php should be safe enough.

like image 190
yivi Avatar answered Oct 17 '22 09:10

yivi