도메인이 다른 홈페이지에 쿠키 저장

도메인이 다른 홈페이지에 쿠키 저장

QA

도메인이 다른 홈페이지에 쿠키 저장

본문

a.com과 b.com 두 사이트 모두 관리중이고 동일 서버에 있습니다.

 

b.com/test/index.php 에서 a.com을 frame으로 띄워주고 있습니다.

 

그런데, a.com 에서 팝업 등을 24시간동안 안보이게 하거나, 쿠키/세션이 필요할 때 통하지 않아 구글링으로 우회하여 a.com에 있는 팝업 닫기 쪽 스크립트에 ajax로 b.com/test/set_cookie.php를 호출하여 쿠키를 저장하려고 했으나 잘 되지 않아 문의합니다.

$.ajax({
            type: 'GET',
            crossDomain: true,
            url: "//b.com/test/set_cookie.php",
            cache: false,
            data : {cookieid:cookieid, onday : onday},
            contentType: "application/x-www-form-urlencoded; charset=utf-8",
            dataType: 'json',
            xhrFields: {
                withCredentials: true
            },
            success: function(data, textStatus, xhr) {
                console.log(data);
                console.log(textStatus);
                console.log(xhr);
            },
            error:function(request,status,error){
                console.log("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
            }

        });

 

이렇게 코드를 작업하고 b.com/test/set_cookie.php 쪽에 제대로 값도 넘어가지만

막상 set_cookie.php  파일에서의

 

header('Access-Control-Allow-Origin: https://a.com');
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Methods: GET, POST");
header("Access-Control-Allow-Headers: Content-Type, *");
header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP"');

 

$id = trim($_GET["cookieid"]);
$onday = trim($_GET["onday"]);

 

setcookie($id, true, time() + (86400 * $onday), '/');

 

쿠키는 제대로 저장되지 않고 있습니다.

딱히 에러도 없습니다..ㅜㅜ

 

어떻게 해야 쿠키가 저장될까요..?

도움을 요청합니다.

 

이 질문에 댓글 쓰기 :

답변 2

같은 도메인내 2차도메인이면 쿠키 굽기가 가능 하나.

 

전혀 다른 도메인 일경우 불가능 합니다.

 

구지 하려 하려면 하겠지만

 

보안에 매우 취약 합니다./

답변을 작성하시기 전에 로그인 해주세요.
전체 123,122 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT