<head>
	<link rel="stylesheet" href="assets/css/bootstrap.css" />
</head>
<?php 
session_start();
function getkeys()
{
    echo "\n\t\t\n\t\t<form class=\"form-horizontal\" method=\"post\" action=\"\">\n<fieldset>\n\n<!-- Form Name -->\n<legend style=\"text-align: center;\">FourSquare Credentials</legend>\n\n<!-- Text input-->\n<div class=\"form-group\">\n  <label class=\"col-md-4 control-label\" for=\"clientid\">Client ID</label>  \n  <div class=\"col-md-4\">\n  <input id=\"clientid\" name=\"clientid\" placeholder=\"Client ID\" class=\"form-control input-md\" required=\"\" type=\"text\">\n    \n  </div>\n</div>\n\n<!-- Text input-->\n<div class=\"form-group\">\n  <label class=\"col-md-4 control-label\" for=\"clientsecret\">Client Secret</label>  \n  <div class=\"col-md-4\">\n  <input id=\"clientsecret\" name=\"clientsecret\" placeholder=\"Client Secret\" class=\"form-control input-md\" required=\"\" type=\"text\">\n    \n  </div>\n</div>\n\n<!-- Button -->\n<div class=\"form-group\">\n  <label class=\"col-md-4 control-label\" for=\"submit\"></label>\n  <div class=\"col-md-4\">\n    <input type=\"submit\" id=\"submit\" name=\"submit\" class=\"btn btn-primary\">\n  </div>\n</div>\n\n</fieldset>\n</form>\n\t\t\n\t\t";
}
$redirect_uri = "http://deepakgoel-1156.appspot.com/foursquare_authentication_token_generator.php";
if (empty($_POST["clientid"]) && empty($_SESSION["clientid"])) {
    getkeys();
} else {
    if (!array_key_exists("code", $_GET)) {
        $client_key = $_POST["clientid"];
        $client_secret = $_POST["clientsecret"];
        $_SESSION["clientid"] = $client_key;
        $_SESSION["clientsecret"] = $client_secret;
        echo "<a href='https://foursquare.com/oauth2/authenticate?client_id=" . $client_key . "&response_type=code&redirect_uri=" . $redirect_uri . "'>Connect to this app via Foursquare</a>";
    } else {
        $client_key = $_SESSION["clientid"];
        $client_secret = $_SESSION["clientsecret"];
        $params = array("client_id" => $client_key, "client_secret" => $client_secret, "grant_type" => "authorization_code", "redirect_uri" => $redirect_uri, "code" => $_GET['code']);
        $body = "https://foursquare.com/oauth2/access_token?" . http_build_query($params);
        $opts = array('http' => array('method' => 'GET', 'ignore_errors' => '1'));
        $context = stream_context_create($opts);
        $stream = fopen($body, 'r', false, $context);
        // actual data at $url
        $result = stream_get_contents($stream);
        $token = json_decode($result, true);
        $token = $token["access_token"];
<?php

$keys = getkeys();
$expired_keys = getexpiredkeys();
$config = getconfig();
$count = 0;
$server_running = checkServer();
?>
<h1>Server Status and Statistics <?php 
if (isAdministrativeUser()) {
    echo ' - Administrator';
}
?>
</h1>
<h2>Legend</h2>
<p><ul>
    <li><b>Available Keys:</b> Shows how many <b>not</b> expired keys  are available on the database.</li>
    <li><b>Maximum connections  Per Key (default: 15) (New) :</b> The maximum number of <b>concurrent</b> connections the server can handle for <b>each key</b>. When this number is reached the server stops for protecting the keys</li>
    <li><b>Active Connections:</b> The current number of concurrent connections. Refreshed every 10 sec. <b>When the server has no Validation Data or the key is overloaded then this is set to 999 for allowing a 4s to connect</b></li>
    <li><b>Maximum Keyload - (default: 500):</b> The maximum Requests based upon Session. When this value is reached the key pauses</li>
    <li><b>Keyload Dropdown -(default: 100):</b> How much the keyload will drops after the keyload interval has passed </li>
    <li><b>Keyload Dropdown Interval - (default: 1200):</b> How often the agent will check for an overloaded key and dropdown the keyload (see above)</li>
</ul></p>
<br />
<table>
    <tr>
        <th>Server status</th>
        <td>
            <?php 
if ($server_running == true) {
    echo '<p class="notification green">ON</p>';