alert('잘못된 경로로 접근한것 같습니다.'); location.href='/login.siso'; "); exit; } if ($_GET["code"]) { //사용자 토큰 받기 $code = $_GET["code"]; $params = sprintf('grant_type=authorization_code&client_id=%s&redirect_uri=%s&code=%s', KAKAO_CLIENT_ID, KAKAO_CALLBACK_URL, $code); $TOKEN_API_URL = "https://kauth.kakao.com/oauth/token"; $opts = array( CURLOPT_URL => $TOKEN_API_URL, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSLVERSION => 1, // TLS CURLOPT_POST => true, CURLOPT_POSTFIELDS => $params, CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false ); $curlSession = curl_init(); curl_setopt_array($curlSession, $opts); $accessTokenJson = curl_exec($curlSession); curl_close($curlSession); //echoAr($accessTokenJson); $responseArr = json_decode($accessTokenJson, true); $_SESSION['kakao_access_token'] = $responseArr['access_token']; $_SESSION['kakao_refresh_token'] = $responseArr['refresh_token']; $_SESSION['kakao_refresh_token_expires_in'] = $responseArr['refresh_token_expires_in']; //사용자 정보 가저오기 $USER_API_URL= "https://kapi.kakao.com/v2/user/me"; $opts = array( CURLOPT_URL => $USER_API_URL, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSLVERSION => 1, CURLOPT_POST => true, CURLOPT_POSTFIELDS => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => array("Authorization: Bearer " . $responseArr['access_token'] ) ); $curlSession = curl_init(); curl_setopt_array($curlSession, $opts); $accessUserJson = curl_exec($curlSession); curl_close($curlSession); $me_responseArr = json_decode($accessUserJson, true); //echoAr($me_responseArr); if ($me_responseArr['id']!="") { // 회원아이디(kakao_ 접두사에 네이버 아이디를 붙여줌) //$mb_uid = 'kakao_'.$me_responseArr['id']; // 회원가입 DB에서 회원이 있으면(이미 가입되어 있다면) 토큰을 업데이트 하고 로그인함 $m_id = $me_responseArr['id']; $chkProfile = getValue("_MEMBER"," where m_id='".$m_id."' and m_logintype='kakao'","ar","*",false); if ($chkProfile) { // 멤버 DB에 토큰값 업데이트 $responseArr['access_token'] // 로그인 $MEMIDX = $chkProfile["m_idx"]; if($chkProfile["m_level"]=="user") { $_SET_LEVEL = "1"; $locationUrl = "index.siso"; }else{ $_SET_LEVEL = "1"; $locationUrl = "reg_profile.siso?idx=".$MEMIDX; } }else { // 회원정보가 없다면 회원가입 // 회원아이디 //$mb_uid // properties 항목은 카카오 회원이 설정한 경우만 넘겨 받습니다. $mb_nickname = $me_responseArr['properties']['nickname']; // 닉네임 $mb_profile_image = $me_responseArr['properties']['profile_image']; // 프로필 이미지 $mb_thumbnail_image = $me_responseArr['properties']['thumbnail_image']; // 프로필 이미지 $mb_email = $me_responseArr['kakao_account']['email']; // 이메일 $mb_gender = $me_responseArr['kakao_account']['gender']; // 성별 female/male $mb_age = $me_responseArr['kakao_account']['age_range']; // 연령대 $mb_birthday = $me_responseArr['kakao_account']['birthday']; // 생일 // 멤버 DB에 토큰과 회원정보를 넣고 로그인 // 멤버 DB에 토큰과 회원정보를 넣고 로그인 $isql = "insert into _MEMBER set m_id='".$m_id."', m_pass='".$m_id."', m_email='".$mb_email."', regdate = now(), m_ip = '".$_SERVER["REMOTE_ADDR"]."', m_agent = '".$_SERVER["HTTP_USER_AGENT"]."', m_expire_date = '0000-00-00', m_expire_time = '00:00:00', m_use = 'Y', m_level = 'user', m_lastlogindate = now(), m_logintype='kakao',m_name='".$mb_nickname."', m_gender='".$mb_gender."',m_birth='".$mb_birthday."' "; $irs = query($isql); if($irs) { $MEMIDX = insert_id(); $SET_LEVEL = "1"; $locationUrl = "reg_profile.siso?idx=".$MEMIDX; if($mb_email) { $maillink = "https://lifeadvisor.ncue.net/mailaccept.php?midx=".$MEMIDX."&memail=".$profile["email"]; $mailcontents = "아래 이메일 주소를 클릭하여 정식회원이 되세요.
인증 하기"; //1. 이메일 인증 메일 전송 //$sendMail = sendMail('yds5004@naver.com', '인연톡', '인연톡 이메일 인증' ,$mailcontents, $profile["email"], "인연톡 임시회원", true); } }else{ echo (" "); exit; } } //회원이 로그인처리했다고 파악하고 세션 생성후 메인페이지로 보낸다. setSession('_IDX', $MEMIDX); setSession('_LEVEL', $_SET_LEVEL); setSession('ltype', "kakao"); setCookie('_LEVEL', $_SET_LEVEL, time()+2678400, '/', '.'._HOST); setCookie('_PW_NPLACE_SAVE',$m_id, time()+2678400,'/', _HOST); echo (" "); exit; } else { // 회원정보를 가져오지 못했습니다. echo (" "); //msg('잘못된 카카오 로그인 정보입니다.','index.siso'); //exit; } } ?>