I'm trying to set session id by using Set-Cookie header. Angular 2 code:
let headers = new Headers(); //Headers
headers.append('Set-Cookie', 'PHPSESSID=' + sha1(APP_CONFIG.localHost) + '; path=/'); //Setting my own cookie id
let options = new RequestOptions({ //Set request options
headers: headers,
withCredentials: true
});
this.http.get(url, options);
So I want to set my own cookie id on server but it isn't in headers.
How to do this right?
At PHP server I use this code:
$this->app->headers
->addHeader('Access-Control-Allow-Origin', 'http://localhost:8100') //Разрешаем запросы к API со всех доменов
->addHeader('Access-Control-Allow-Methods', 'POST, GET, OPTIONS')
->addHeader('Access-Control-Allow-Headers', 'Set-Cookie, Content-type')
->addHeader('Access-Control-Allow-Credentials', 'true')
->addHeader('Content-type', 'application/json; charset=utf-8');
The solution was that I need to use not Set-Cookie header. I need to use Cookie header. But the problem is that my Google Chrome browser is refuse it. The solution is to query server with this parameter that contains session_id. And at server side set it.