function apiRequest($url, $post=FALSE, $headers=array()) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); if($post) curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post)); $headers = [ 'Accept: application/vnd.github.v3+json, application/json', 'User-Agent: http://example-app.com/' ]; if(isset($_SESSION['access_token'])) $headers[] = 'Authorization: Bearer '.$SESSION['access_token']; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); return json_decode($response, true); } $githubClientID = 'Ov23li271OczQKR6ISyL' $githubClientSecret = '9df1c6e9fa98690dbcc9ed12676dc2adcc1cf8cf'; $authorizeURL = 'https://github.com/login/oauth/authorize'; $tokenURL = 'https://github.com/login/oauth/access_token'; $apiURLBase = 'https://api.github.com/'; $baseURL = 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']; session_start(); if(!isset($_GET['action'])) { if(!empty($_SESSION['access_token'])) { echo '