ob_start(); session_start(); $_SESSION['id'] = session_id(); if (!isset($cookie_life_days)) {$cookie_life_days = 60;}; if (!isset($_SESSION['page_action'])) { $_SESSION['page_action']='verify_login'; }; if ($_REQUEST['page_action'] =='welcome') { $_SESSION['page_action']='welcome';} else if ($_REQUEST['page_action'] =='verify_login') { $_SESSION['page_action']='verify_login';} else if ($_REQUEST['page_action'] =='logout_request') { $_SESSION['page_action']='logout_request';}; if ($_SESSION['page_action']=='verify_login'){ if (isset($_COOKIE['exchange'])){ ob_end_clean(); ob_start(); $_SESSION['page_action']='welcome'; header('Location: '.$_SERVER['PHP_SELF']); exit(); } if (isset($_POST['flo_id'], $_POST['pub_key'], $_SESSION['id'], $_POST['sign'] )){ ob_start(); function callAPI($method, $url, $data){ $curl = curl_init(); switch ($method){ case "POST": curl_setopt($curl, CURLOPT_POST, 1); if ($data) curl_setopt($curl, CURLOPT_POSTFIELDS, $data); break; case "PUT": curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); if ($data) curl_setopt($curl, CURLOPT_POSTFIELDS, $data); break; default: if ($data) $url = sprintf("%s?%s", $url, http_build_query($data)); } // OPTIONS: curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'APIKEY: 111111111111111111111', 'Content-Type: application/json', )); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); // EXECUTE: $result = curl_exec($curl); if(!$result){die("Connection Failure");} curl_close($curl); return $result; } $floID = $_POST['flo_id']; $pubKey = $_POST['pub_key']; $s_id = $_SESSION['id']; $sign = $_POST['sign']; $data_array = array( "floID" => $floID, "pubKey" => $pubKey, "message" => $s_id, "sign" => $sign ); $make_call = callAPI('POST', 'https://flo-sign-validator.duckdns.org', json_encode($data_array)); $response = json_decode($make_call, true); if ($response['success'] == 1) { //store $s_id (session ID) in SQl ob_end_clean(); ob_start(); setcookie("exchange[flo_id]", $floID, time () + (86400 * $cookie_life_days)); setcookie("exchange[session_id]", $s_id, time () + (86400 * $cookie_life_days)); setcookie("exchange[pub_key]", $pubKey,time () + (86400 * $cookie_life_days)); $_SESSION['page_action']='welcome'; header('Location: '.$_SERVER['PHP_SELF']); exit(); } else { echo ''; } } echo << Login using FLO Private Key Enter your FLO Private Key END; } if ($_SESSION['page_action']=='welcome'){ if (!isset($_COOKIE['exchange'])) { $_SESSION['page_action']='verify_login'; ob_end_clean(); ob_start(); header('Location: '.$_SERVER['PHP_SELF']); exit(); } echo << Exchange Welcome Logged in as {$_COOKIE['exchange']['flo_id']} END; } if ($_SESSION['page_action']=='logout_request'){ if (isset($_COOKIE['exchange'])) { unset($_COOKIE['exchange[flo_id]']); setcookie('exchange[flo_id]', null, -1); unset($_COOKIE['exchange[session_id]']); setcookie('exchange[session_id]', null, -1); unset($_COOKIE['exchange[pub_key]']); setcookie('exchange[pub_key]', null, -1); unset($_COOKIE['exchange']); setcookie('exchange', null, -1); } ob_end_clean(); ob_start(); $_SESSION['page_action']='verify_login'; header('Location: '.$_SERVER['PHP_SELF']); exit(); } ?>