You are using Adblock Extension

We apologize for the inconvenience, but using Adblock to block your source of income from the site. The site is built on self-support across ads. Please exclude our site from the Adblock extension.
Time Now: 16 November 2018 , 18:38:05 Next Reset In: 14 Days, 5 Hours, 21 Minutes, 58 Seconds.

The Most Visited Top Servers Website And The Best For Kal-Online Players

Vote & Rewards API (Documentation)

Html Vote Code (Not API)

Paste this code anywhere in your website.

Replace Server_Vote_URL with your server vote link.

<!-- TOP-KAL.COM -->
<a href="Server_Vote_URL" target="_blank" style="cursor: pointer;">
<img border="0" src="https://top-kal.com/assets/images/vote_image.jpg" alt="TOP-KAL.COM" />
</a>
<!-- TOP-KAL.COM-->

Vote & Rewards API Documentation

API Installtion Step by Step for Kal-Online Category

Before start using Vote & Rewards Api , You have to execute this SQL Query in your database then restart [MainServer] to be sure that rewards will be inserted without problems , you can execute this query multiple times it will not cause any bugs in your database.
use [kal_db]
IF NOT EXISTS(select [IID] FROM Item WHERE [IID] = 1)
BEGIN
   INSERT INTO Item ( [PID], [IID], [Index], [Prefix], [Info], [Num]) VALUES ( 1, 1, 1, 0, 0, 1 )
END
IF NOT EXISTS(select [IID] FROM Item WHERE [IID] = '-2147483647')
BEGIN
   INSERT INTO Item ( [PID], [IID], [Index], [Prefix], [Info], [Num]) VALUES ( 1, '-2147483647', 1, 0, 0, 1 )
END
Paste the following button anywhere in your site and if you using BeshoyFD Userpanel paste it in includes/template.php , Line 365.
<script type='text/javascript'>function vote_rewards_popup(){window.open('/vote-rewards.php', 'TOP-KAL.COM | Top KalOnline Private Servers', 'toolbar=no, location=no,directories=no, status=no, menubar=no,resizable=no, copyhistory=no, width=600, height=400, top='+(screen.height/2)-(400/2)+', left='+(screen.width/2)-(600/2));};</script>
<li><a href='#' onclick='vote_rewards_popup();return false;' style='display: inline-table;cursor: pointer;'><img src='https://top-kal.com/assets/images/vote_image_btn.png' /></a></li>

Create vote-rewards.php in your website files and paste source code to it or Download File and copy it to your website files.
Path of file should be like : http://yourdomain.com/vote-rewards.php.

full source code for Vote & Rewards

Replace YOUR SERVER API KEY with your server api key.

You can find api key in Manage ServersEdit Server Options & Features.

Change ODBC Connection and Vote Rewards Settings , to your own settings.

In API callback Replace [YOUR_DOMAIN] to your website domain.

<?php
session_start(); //if you using any userpanel you can use the session to get account id 
error_reporting(0);

/***** Vote Rewards API Settings of top-kal.com *******/
$API["secret_key"] = "TiXTuaHIQFGbLWx"; // random key for more security 
$API["api_key"] = "YOUR SERVER API KEY"; //api key of your server on top-kal.com , you can find it in manage servers > edit server > Options & Features
$API["callback"] = "http://[YOUR_DOMAIN]/vote-rewards.php?return={RETURNEDCODE}"; //the path of this file in your website ex[domain/vote-rewards.php?return={RETURNEDCODE}] , replace domain with your server domain
$API["API_Domain"] = "http://api.top-kal.com";


/*************************START KAL-Online Category For Vote & Rewards API ******************************************/

/***** ODBC Connection Setting *******/
$config["db_username"] = "sa";
$config["db_password"] = "*********";
$config["db_database_account"] = "kal_auth";
$config["db_database_player"] = "kal_db";
$config["db_server"] = "*******\SQLEXPRESS";
$config["db_driver"] = "SQL Server";

/*************** Minimum Character Level To Vote and rewards Settings *******************/
$config["MinLvl_Require"] = 50; // there should be at least one character in account higher than that level to able to vote and get rewards.
$config["Reward_Index"] = 447; // index of reward
$config["Reward_Amount"] = 50; // amount
$config["Reward_Bound"] = true; // insert rewards as bound item

/*******************************************************************/


function InsertRewards($account_unique_id){ //function to insert rewards
	global $config;

    $connect = odbc_connect('Driver={'.$config["db_driver"].'};Server='.$config["db_server"].';Database='.$config["db_database_player"].';', $config['db_username'] ,$config['db_password']); //odbc connection
	
	if(!$connect)
		return false;

	$query = odbc_exec($connect,"SELECT Top 1 [IID] FROM [Item] Where [IID] < 1 order by IID Desc"); //get last negative iid to insert item without problems
	if(!$query)
		return false;

	$data = odbc_fetch_array($query);
	if($data && !empty($data) && isset($data["IID"])) // insert rewards
		odbc_exec($connect,"INSERT INTO [Item] ([PID],[IID],[Index],[Prefix],[Info],[Num])VALUES ($account_unique_id,".($data["IID"]+1).",".$config["Reward_Index"].",0,".(16+($config["Reward_Bound"] ? 128 : 0)).",".$config["Reward_Amount"].")"); //insert rewards
	
}

function CheckCharacters($AccountUID){ //function to check minimum characters level
	global $config;

    $connect = odbc_connect('Driver={'.$config["db_driver"].'};Server='.$config["db_server"].';Database='.$config["db_database_player"].';', $config['db_username'] ,$config['db_password']); //odbc connection
	
	if(!$connect)
		return array("error" => "failed to connect to database players.");

	$query = odbc_exec($connect,"SELECT [Level] FROM [Player] WHERE[UID] = $AccountUID"); //query to get list of characters
	if(!$query)
		return array("error" => "failed to find characters in this account id.");

	while($r = odbc_fetch_array($query)){
		if($r["Level"]  >= $config["MinLvl_Require"]) //check level of characters
		return array("success" => $AccountUID);
	}
  return array("error" => "You should have one character at least higher than level : ".$config["MinLvl_Require"]." to can vote.");
}

function CheckAccount($AccountID){ //function to check account if exists and get unqiue id of account (UID)
	global $config;

    $connect = odbc_connect('Driver={'.$config["db_driver"].'};Server='.$config["db_server"].';Database='.$config["db_database_account"].';', $config['db_username'] ,$config['db_password']); //odbc connection
	
	if(!$connect)
		return array("error" => "failed to connect to database accounts.");

	$query = odbc_exec($connect,"SELECT TOP 1 [UID] FROM [Login] WHERE[ID] = '$AccountID'"); //query to check if account exists
	if(!$query)
		return array("error" => "this account id not exists.");

	$data = odbc_fetch_array($query); // check if account exists or not
	if(!$data || empty($data) || !isset($data["UID"]))
		return array("error" => "this account id not exists.");

	if($config["MinLvl_Require"] > 0)
		  return CheckCharacters($data["UID"]);
	  
  return array("success" => $data["UID"]);
}

/*************************END KAL-Online Category For Vote & Rewards API ******************************************/


$response = array("error" => false , "success" => false , 'redirect' => false);

function post_content($query){
$query_array = array();foreach( $query as $key => $key_value )$query_array[] = urlencode( $key ) . '=' . urlencode( $key_value );return implode( '&', $query_array );
}

function postParams($content){ //post request parameters to https://top-kal.com api
	global $API;
	$opts = array('http' =>  array('method'  => 'POST',"header" => "Content-type: application/x-www-form-urlencoded\r\nAuthorization:".base64_encode($API["api_key"].":".$API["secret_key"])."\r\n", "content" => post_content($content)));return stream_context_create($opts);
}

function Submit(){ //submit function
	global $API;

	if (empty($_POST['account']) || !ctype_alnum($_POST['account'])) // account id validation
		return array(	"error" => "Invalid account id.");
		
	$CheckAccount = CheckAccount($_POST['account']); //check if account exists

	if (isset($CheckAccount["error"]))
		return array("error" => $CheckAccount["error"]);

	if (isset($CheckAccount["success"])){
		// you can use session to get account uid or get responsed account id , its a unique id for each account
		$account_unique_id = (isset($_SESSION['kal_id'])) ? $_SESSION['kal_id'] : $CheckAccount["success"]; 

		// send request to get token
		$result = json_decode(file_get_contents($API["API_Domain"] . '/api/generate/vote-rewards-token', false, postParams(array('callback' => $API["callback"],'account_unique_id' => $account_unique_id	))) , true);
		if (!empty($result)){
			if (isset($result["response"])){
				if (isset($result["response"]["error"]))
					return array("error" => $result["response"]["error"]);
				elseif (isset($result["response"]["success"])) // redirect to https://top-kal.com to vote
					return array("redirect" => '<script type="text/javascript">setTimeout(function () { window.location.href = "'.$result["response"]["success"].'";}, 500)</script>');
			}
		}
	}
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['account'])){ // form submitted
	$response = Submit();
	if (isset($response['redirect']) && $response['redirect']){
		echo $response['redirect'];
		die;
		}
}elseif (isset($_GET['return'])){ // response after voting to receive rewards
	$result = json_decode(file_get_contents($API["API_Domain"] . '/api/verify/vote-rewards-token', false, postParams(array('returned_code' => $_GET['return']))) , true);
	if (!empty($result)){
		if (isset($result["response"])){
			if (isset($result["response"]["error"])) $response['error'] = $result["response"]["error"];
			elseif (isset($result["response"]["success"])){
				InsertRewards($result["response"]["account_unique_id"]); //insert rewards to account
				$response['success'] = '<b>Thank you, Your vote has been recorded and the server rank will be updated soon.<b><br />You will receive your rewards in storage of your account.<p>Your next vote in : <b>' . $result["response"]["NextVote"] . '</b></p>';
				}
			}
		}
	}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en">
<head>
    <title>TOP-KAL.COM | Top KalOnline Private Servers</title>
</head>
<body>
<!---------- HTML FORM -------------->
<form action="" method="post" class="smart-form">
<h1>TOP-KAL.COM<br>Top KalOnline Private Servers<hr> <span>Vote and get rewards.</span> </h1>
<noscript><div class="isa_error">Javascript is not enabled in your browser , Enable it or change browser.</div></noscript>
<?php if(isset($response['error']) && $response['error']){ ?><div class="isa_error"> <?php echo $response['error'] ;?> </div> <?php } ?>
<?php if(isset($response['success']) && $response['success']){ ?><div class="isa_success"> <?php echo $response['success'] ;?> </div>
<?php }else{ ?>
    <label>
        <span>Your Account ID :</span>
        <input  type="text" name="account" maxlength="20" <?php echo (isset($_SESSION['kal_username'])) ? 'readonly value="'.$_SESSION['kal_username'].'"' : ""; ?>" />
    </label>
     <label class="label_btn">
        <input type="submit" class="button" value="Vote" /> 
    </label> 
<?php } ?>	
 <label class="footer"><br><hr><b>Top KalOnline Private Servers</b><br>Copyright 2018 &copy; TOP-KAL.COM , All rights reserved.</label> 
</form>
<!---------- END HTML FORM -------------->
</body>
<!---------- STYLE -------------->
<style rel="stylesheet" type="text/css" >
.smart-form .footer {text-align:center;}.smart-form{margin-left:auto;margin-right:auto;max-width:500px;background:#F8F8F8;padding:30px 30px 20px;font:12px Arial,Helvetica,sans-serif;color:#666;border-radius:5px;-webkit-border-radius:5px;-moz-border-radius:5px}.smart-form h1{font:24px "Trebuchet MS",Arial,Helvetica,sans-serif;padding:20px 0;display:block;margin:-30px -30px 10px;color:#FFF;background:#5fafc4;text-shadow:1px 1px 1px #949494;border-radius:5px 5px 0 0;-webkit-border-radius:5px 5px 0 0;-moz-border-radius:5px 5px 0 0;border-bottom:1px solid #4cafa1;text-align:center}.smart-form h1>span{display:block;font-size:20px;color:#fff065}.smart-form label{display:block;margin:0 0 5px}.smart-form label>span{float:left;margin-top:10px;color:#5E5E5E}.smart-form input[type=text],.smart-form input[type=email],.smart-form select,.smart-form textarea{color:#555;height:30px;line-height:15px;width:100%;padding:0 0 0 10px;margin-top:2px;border:1px solid #E5E5E5;background:#FBFBFB;outline:0;-webkit-box-shadow:inset 1px 1px 2px rgba(238,238,238,.2);box-shadow:inset 1px 1px 2px rgba(238,238,238,.2);font:400 14px/14px Arial,Helvetica,sans-serif}.smart-form textarea{height:100px;padding-top:10px}.smart-form select{background:url(down-arrow.png) right no-repeat,-moz-linear-gradient(top,#FBFBFB 0,#E9E9E9 100%);background:url(down-arrow.png) right no-repeat,-webkit-gradient(linear,left top,left bottom,color-stop(0,#FBFBFB),color-stop(100%,#E9E9E9));appearance:none;-webkit-appearance:none;-moz-appearance:none;text-indent:.01px;text-overflow:'';width:100%;height:30px}.smart-form .button{background-color:#9DC45F;border-radius:5px;-webkit-border-radius:5px;-moz-border-border-radius:5px;border:none;padding:10px 25px;color:#FFF;text-shadow:1px 1px 1px #949494;cursor:pointer}.smart-form .button:hover{background-color:#80A24A}.smart-form .label_btn{text-align:center;padding:10}.isa_error,.isa_success{margin:10px 0;padding:12px}.isa_success{color:#4F8A10;background-color:#DFF2BF}.isa_error{color:#D8000C;background-color:#FFD2D2}.isa_error i,.isa_success i{margin:10px 22px;font-size:2em;vertical-align:middle}.smart-form input[type=text]:read-only{background-color: #dbdbdb;}.smart-form input[type=text]:-moz-read-only{background-color: #dbdbdb;}
</style>
<!---------- END -------------->
</html>

Installation Video

If you couldn't install api or stucked in any step , feel free to chatting with us through Live Support