0

I'm trying to send a cookie whose name contains two dots. this is my code

$response = Http::withHeaders([
    'Cookie'    => '.cookie.withdots=test-value'
])->get('http://example.com');

now when I send this request to my system on another route and print the cookies dots(.) has transformed to underscores(_)

array:1 [
  "_cookie_withdots" => "test-value"
]

I need them to stay as dots(.) what can i do guys?

  • I deleted my answer, I postet some wrong information there. Check in the network tab with the browser: The dots are set in `Set-Cookie` and they are returned in `Cookie` header, but PHP replaces dots in incoming variables by `_` automatically. – Daniel W. Dec 14 '21 at 17:35
  • @DanielW. a cookie name is not a PHP variable though. Array indices have no problem containing a dot. – miken32 Dec 14 '21 at 20:26
  • You are sending this to your own system? Just get rid of the dots then. – miken32 Dec 14 '21 at 20:29
  • @miken32 When PHP receives a value via HTTP it automatically turns dots into underscores. Same for Cookie headers, same for GET variables. – Daniel W. Dec 15 '21 at 09:13

1 Answers1

-1

There is a dedicated method to set the cookies: https://laravel.com/docs/8.x/responses#attaching-cookies-to-responses

return response('Hello World')->cookie(
 '.cookie.withdots', 'test-value', 10
);
Akbar khan
  • 54
  • 1
  • 4