2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CORS Cookie について

Last updated at Posted at 2014-09-09

同一ドメインの場合

PHPでhttp onlyの設定を解除すれば、取得可能。

$.post(url, params)
	.done(function(res, status, XHR) {
		console.log('url: '+url+' OK');
		var cookie = XHR.getResponseHeader('Set-Cookie');
	})
	.fail(function(XHR, status, res) {
		console.log('url: '+url+' NG');
		console.log(status);
	});

外部ドメインの場合

サーバー間通信では取得可能だがjavascriptでは、取得はできない。(たぶん)
ajaxでの送信は出来るかも。

$.post(url, params)
	.done(function(res, status, XHR) {
		console.log('url: '+url+' OK');
		var cookie = XHR.getResponseHeader('Set-Cookie');
	})
	.fail(function(XHR, status, res) {
		console.log('url: '+url+' NG');
		console.log(status);
	});

$response->set_header('Access-Control-Allow-Origin', 'http://localhost');
        $response->set_header('Access-Control-Allow-Headers', 'Content-Type, X-Requested-With');
        $response->set_header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
        $response->set_header('Access-Control-Max-Age', 0);
        $response->set_header('Content-Language', 'ja');
        $response->set_header('Content-Type', 'application/json; charset=utf-8');

		 // cookieなどの情報を送るかどうか
        $response->set_header('Access-Control-Allow-Credentials', 'true');
		 // 3パーティーからの書き込みを許可するか?(IE対策?)
        $response->set_header("P3P", "CP='CAO PSA OUR'");

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?