최근 브라우져 설치및 업데이트시 기본값으로 아래의 값으로 설정되어
이니시스등 카드 결제시 쿠키 및 세션이 끊기는 현상발생하여 결제 오류가 나타납니다.
- 크롬 브라우져
주소창 : chrome://flags/#same-site-by-default-cookies
SameSite by default cookies 설정값 Default
- 마이크로소프 엣지 브라우져
주소창 : edge://flags/#same-site-by-default-cookies
SameSite by default cookies 설정값 Default
- 파이어폭스 브라우져
주소창 : about:config
network.cookie.sameSite.laxByDefault 설정값 true
이를 해결하기 위해 결제 페이지에 아래 코드를 삽입하세요.
<?
if(!function_exists('session_start_samesite')) {
function session_start_samesite($options = array())
{
$res = @session_start($options);
$headers = headers_list();
krsort($headers);
$i = 0;
foreach ($headers as $header) {
if (!preg_match('~^Set-Cookie: PHPSESSID=~', $header)) continue;
$header = preg_replace('~; secure(; HttpOnly)?$~', '', $header) . '; secure; SameSite=None';
header($header, false);
$i++;
break;
}
// PHPSESSID 쿠키가 헤더에 등록되어있지 않으면 추가해준다.
if($i == 0)
{
$header = "Set-Cookie: cross-site-cookie=PHPSESSID; secure; SameSite=None";
header($header, false);
}
return $res;
}
}
session_start_samesite();
?>
접속 브라우져의 설정값이 크롬(disbled), 엣지(disbled), 파이어폭스(false) 일경우 에러가 나타나지 않습니다.
'프로그래밍 > PHP' 카테고리의 다른 글
JSON PHP 로 SendGrid 메일 API 연동 (0) | 2020.11.27 |
---|---|
멀티파일 메일 보내기 (0) | 2020.06.09 |
PHP 에서 동적 변수명 사용 (0) | 2020.05.05 |