Welcome Guest, Not a member yet? Register   Sign In
Config cookie not work, and get_cookie cannot get cookie
#1
Information 

I have a class like this:

PHP Code:
<?php

namespace App\Controllers;

class 
Home extends BaseController
{
    public function index()
    {
        return view('welcome_message');
    }

    public function cookie()
    {
        helper('cookie');
        set_cookie(['name' => 'TTT''value' => '456']);
        $data = [
            'success' => true,
            'id'      => 123,
            'get_cookie' => get_cookie('TTT')
        ];

        return $this->response->setJSON($data);
    }
}
In app\Config\Cookie.php I set 
Code:
<?php
public $expires = 30 * 24 * 60 * 60 * 1000;
public $domain = 'localhost:2000';
public $httponly = true;
?>
In browser I see httpOnly is false, why set_cookie function dont get option from config file? But some other options are working, I uncomment .env file set httponly is true it's not working too. 
[Image: image.png]
I why in the client I call to cookie() function why get_cookie('TTT') return null. This is my code:
Code:
const instance = axios.create({
    withCredentials: true,
    baseURL: 'http://code4.local',
})
instance.post(
    '/api/cookie',
    {"access_token":"ABC"}
)
And response header:
Code:
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: http://localhost:2000
Cache-control: no-store, max-age=0, no-cache
Connection: Keep-Alive
Content-Type: application/json; charset=UTF-8
Date: Wed, 10 Aug 2022 07:23:24 GMT
Keep-Alive: timeout=5, max=100
Server: Apache/2.4.41 (Ubuntu)
Set-Cookie: TTT=456; path=/; domain=localhost:2000; SameSite=Lax
Transfer-Encoding: chunked
Vary: Origin
And request header:

Code:
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate
Accept-Language: vi,en-US;q=0.9,en;q=0.8,ja;q=0.7
Connection: keep-alive
Content-Length: 22
Content-Type: application/json
Host: code4.local
Origin: http://localhost:2000
Referer: http://localhost:2000/
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.0.0 Safari/537.36

I searched on google 3 days but nothing help. Please help me!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB