function apiRequest($url, $post=FALSE, $header=array()) { $ch = curl_init($url); curl_setopt($ch, CURL_RETURNTRANSFER, TRUE); if($post) { curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post)); } $headers = [ 'Accept: application/vnd.github.v3+json, application.json', 'User-Agent: https://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 = 'c0ccda3474e35091fc6c'; $githubClientSecret = '21982a86d5b70bcbf25b37425c1f5db9c32c75a5'; $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['acces_token'])) { echo '

Logged IN

'; echo '

View Repos

'; echo '

Log Out

'; } else { echo '

Not Logged IN

'; echo '

Login

'; } }