Skip to content

Commit 83f787e

Browse files
committed
fix: fix bug with session
1 parent ebfde78 commit 83f787e

File tree

3 files changed

+92
-9
lines changed

3 files changed

+92
-9
lines changed

model/common/token.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,21 @@ public function getToken( $args ) {
4848
}
4949

5050
public function validateToken( $output ) {
51+
if (!function_exists('getallheaders')) {
52+
function getallheaders() {
53+
$headers = [];
54+
foreach ($_SERVER as $name => $value) {
55+
if (substr($name, 0, 5) == 'HTTP_') {
56+
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
57+
}
58+
}
59+
return $headers;
60+
}
61+
}
62+
5163
$headers = getallheaders();
64+
65+
5266
$auth = isset( $headers['Authorization'] ) ? $headers['Authorization'] : false;
5367
if ( ! $auth ) {
5468
return false;

plugin.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,81 @@ function VFA_RestApi( WP_REST_Request $request ) {
9898
'callback' => 'VFA_RestApi',
9999
) );
100100
} );
101+
102+
add_action('wp', function() {
103+
$headers = headers_list();
104+
$cookies = array();
105+
106+
107+
108+
foreach($headers as $header) {
109+
if (strpos($header, 'Set-Cookie: ') === 0) {
110+
if (preg_match('/path=(.*);/i', $header)) {
111+
$cookies[] = preg_replace('/path=(.*);/i', 'path=/;', $header);
112+
} else if (preg_match('/path=(.*)/i', $header)) {
113+
$cookies[] = preg_replace('/path=(.*)/i', 'path=/', $header);
114+
}
115+
116+
}
117+
}
118+
119+
for ($i=0; $i < count($cookies); $i++) {
120+
if($i == 0) {
121+
header($cookies[$i]);
122+
} else {
123+
header($cookies[$i], false);
124+
}
125+
}
126+
},99);
127+
add_action('woocommerce_add_to_cart', function() {
128+
$headers = headers_list();
129+
$cookies = array();
130+
131+
132+
133+
foreach($headers as $header) {
134+
if (strpos($header, 'Set-Cookie: ') === 0) {
135+
if (preg_match('/path=(.*);/i', $header)) {
136+
$cookies[] = preg_replace('/path=(.*);/i', 'path=/;', $header);
137+
} else if (preg_match('/path=(.*)/i', $header)) {
138+
$cookies[] = preg_replace('/path=(.*)/i', 'path=/', $header);
139+
}
140+
141+
}
142+
}
143+
144+
145+
for ($i=0; $i < count($cookies); $i++) {
146+
if($i == 0) {
147+
header($cookies[$i]);
148+
} else {
149+
header($cookies[$i], false);
150+
}
151+
}
152+
},99);
153+
154+
add_action('shutdown', function() {
155+
$headers = headers_list();
156+
$cookies = array();
157+
158+
159+
160+
foreach($headers as $header) {
161+
if (strpos($header, 'Set-Cookie: ') === 0) {
162+
if (preg_match('/path=(.*);/i', $header)) {
163+
$cookies[] = preg_replace('/path=(.*);/i', 'path=/;', $header);
164+
} else if (preg_match('/path=(.*)/i', $header)) {
165+
$cookies[] = preg_replace('/path=(.*)/i', 'path=/', $header);
166+
}
167+
168+
}
169+
}
170+
171+
for ($i=0; $i < count($cookies); $i++) {
172+
if($i == 0) {
173+
header($cookies[$i]);
174+
} else {
175+
header($cookies[$i], false);
176+
}
177+
}
178+
}, 1);

resolver/startup/startup.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,6 @@ public function index()
3737
];
3838
}
3939

40-
$cookie_path = COOKIEPATH ? COOKIEPATH : '/';
41-
42-
if ($cookie_path != '/') {
43-
foreach ($_COOKIE as $key => $value) {
44-
if (strpos($key, 'woocommerce') >= 0) {
45-
setcookie($key, $value, 0, "/");
46-
}
47-
}
48-
}
4940

5041
return $result;
5142
}

0 commit comments

Comments
 (0)