Skip to content

Commit 54a0c3b

Browse files
committed
Cookie domain fix
1 parent ba31c58 commit 54a0c3b

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

config/application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
/**
6868
* URLs
6969
*/
70+
7071
$nginx_port = env('NGINX_PORT') ? ':' . env('NGINX_PORT') : '';
7172

7273
Config::define('NGINX_PORT', env('NGINX_PORT') ?: '');
@@ -164,7 +165,6 @@
164165
Config::define('PATH_CURRENT_SITE', env('PATH_CURRENT_SITE') ?: '/');
165166
Config::define('SITE_ID_CURRENT_SITE', env('SITE_ID_CURRENT_SITE') ?: 1);
166167
Config::define('BLOG_ID_CURRENT_SITE', env('BLOG_ID_CURRENT_SITE') ?: 1);
167-
Config::define('COOKIE_DOMAIN', env('DOMAIN_CURRENT_SITE') ?: env('WP_HOME'));
168168
Config::define('SUNRISE', env('SUNRISE') ?: false);
169169

170170
Config::apply();

web/app/sunrise.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313

1414
// Parse the domain and subdomain from the request
1515
$domain = strtolower($_SERVER['HTTP_HOST'] ?? '');
16-
$base_domain = parse_url($wp_home, PHP_URL_HOST) . $nginx_port;
16+
$base_domain = parse_url($wp_home, PHP_URL_HOST);
17+
$base_domain_with_port = $base_domain . $nginx_port;
1718
$subdomain = null;
1819

1920
// Extract the subdomain if it differs from the base domain
20-
if (strpos(explode('.', $domain)[0], $base_domain) === false) {
21+
if (strpos(explode('.', $domain)[0], $base_domain_with_port) === false) {
2122
$subdomain = explode('.', $domain)[0];
2223
}
2324

@@ -38,7 +39,7 @@
3839
// Set $current_site and $current_blog based on environment variables and dynamic values
3940
$current_site = (object) [
4041
'id' => $site_id,
41-
'domain' => $base_domain,
42+
'domain' => $base_domain_with_port,
4243
'path' => Config::get('PATH_CURRENT_SITE') ?: '/',
4344
'blog_id' => $blog_id,
4445
'public' => 1,
@@ -52,7 +53,7 @@
5253
$current_blog = (object) [
5354
'blog_id' => $blog_id,
5455
'site_id' => $site_id,
55-
'domain' => $subdomain ? $subdomain . '.' . $base_domain : $base_domain,
56+
'domain' => $subdomain ? $subdomain . '.' . $base_domain_with_port : $base_domain_with_port,
5657
'path' => Config::get('PATH_CURRENT_SITE') ?: '/',
5758
'public' => 1,
5859
'archived' => 0,
@@ -62,6 +63,10 @@
6263
'lang_id' => 0,
6364
];
6465

66+
// Set COOKIE_DOMAIN to handle subdomains dynamically
67+
$cookie_domain = $subdomain ? $subdomain . '.' . $base_domain : $base_domain;
68+
define('COOKIE_DOMAIN', $cookie_domain);
69+
6570
// Debugging log to confirm settings in development
6671
if ($environment === 'development') {
6772
error_log("SUNRISE: Detected subdomain '{$subdomain}', setting current_blog->domain to {$current_blog->domain}, blog_id to {$blog_id}, site_id to {$site_id}");

0 commit comments

Comments
 (0)