The Postback Function

Our goal is to make it easy and secure for your users to vote for and support your website and receive incentives such as credits. The system we have in place is quite simple and takes little programming knowledge to impliment.

The Basics

What happens is a user on your site is given a special voting link with their username or userid added to it. When this user votes we then take this username/userid and send it back to your server as a POST to your specified script to process and credit the user for voting. It is really that simple and you just need to enter URL to the script in your user control panel, implement the example script found below, and you are ready to go.

Example Voting Url

https://www.topautosurf.org/index.php?a=in&u=TOPLIST_USERNAME&id=VOTER_USERNAME_OR_ID
You can simply switch out the url in your existing voting code from us as found in your control panel

Example Script

<?php

#Example PHP Postback Script

// Your Database Connection Details
$host        = 'localhost';
$db_name     = '';
$db_user     = ''; 
$db_password = '';

$connection  = mysqli_connect($host, $db_user, $db_password);
mysqli_select_db($connection, $db_name);

$userid = isset($_POST['userid']) ? $_POST['userid']     : null;
$userip = isset($_POST['userip']) ? $_POST['userip']     : null;
$valid  = isset($_POST['voted'])  ? (int)$_POST['voted'] : 0;


// Make sure the user was not yet rewarded on your system
// For example by checking your reward logs
if (!is_null($userid) && $valid == 1) 
{		
    // Make userid safe to use in query
    $userid = mysqli_real_escape_string($connection, $userid);

    // COUNT rows where reward_date is today
    $result = mysqli_query($connection, "SELECT COUNT(*) FROM `reward_log` WHERE `user` = '$userid' AND `reward_date` >= CURDATE()");
    $rewarded = mysqli_num_rows($result);
		
    // No results means not rewarded yet, so grant reward and set the reward date/time log
    if(!$rewarded) 
    {
        // Grant reward, for example points
        mysqli_query($connection, "UPDATE `users` SET `points` = `points` + 1 WHERE `user` = '$userid'");
			
        // Insert log
        mysqli_query($connection, "INSERT INTO `reward_log` (`user`, `reward_date`) VALUES ('$userid', NOW())");
    }
}

// Close connection
mysqli_close($connection);

?>


The extern IP check function

If you quickly want to see if a user voted already simply visit this url
https://www.topautosurf.org/index.php?a=in&u=TOPLIST_USERNAME&ipc=THE_IP_TO_CHECK

As you can see this looks like a normal vote link, but will NOT do any vote, instead it only executes a database query and then returns either 0 or 1 (can be used with cUrl etc.) A 0 returned means the user did not vote on that day when the check was called, 1 means the user voted already.