본문 바로가기
개발/php

php 카카오 로그인 예제

by 향유 2021. 1. 19.
function 함수명 {

​

$rawData = $_POST ? $_POST : $_GET;

//$rawData['token']

// header('Content-Type: application/json; charset=utf-8');

​

$api_url = 'https://kapi.kakao.com/v2/user/me';

$access_token = $rawData['token'];

​

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $api_url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $access_token));

$response = curl_exec($ch);

​

$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

/*

echo 'http code: ' . $http_code . "\n";

​

if (!$response) {

echo 'no response';

exit;

}

print_r($response);

*/

$return_data['a']=$response;

return $response;

​

}

댓글