Here we will show you both which ip's that successfully voted and which ones that voted but failed, you will also be able know what went wrong.
With our pingback system you will know each time a voter has voted and which ip and/or username they have used.
To verify voters using pingUsername, on your site details page on gtop100 where you vote, add
?vote=1&pingUsername=xyz to the url (replace xyz with the pingUsername of your choice)
You are allowed to use A-Z and 0-9 in the "&pingUsername" field, anything else might cause issues.
We allow for ports: 80, 443 and 2000-6000, this is the port range you can use to receive pingbacks to your server.
Below is an example code in PHP how your pingback file could look like.
<?php
// This example is compatable with PHP 8 and can handle both receiving pingbacks via JSON and normal POST.
// It is highly recommended that you use receive pingbacks via JSON as it will lower the load on your server.
// It is important to use prepared statements to prevent SQL injection.
// Also, proper error handling should be implemented.
// Make sure you always return one of these http response codes:
// 200, 201, 202, 203 or 204
// This will prevent extra unnecessary requests to your server.
// We allow for: 80, 443 and 2000-6000 port ranges to receive pingbacks to your server.
$contentType = $_SERVER["CONTENT_TYPE"] ?? "";
// Receive data
if (strpos($contentType, "application/json") !== false) {
$data = json_decode(file_get_contents("php://input"), true);
// Handle JSON Data
if (!$data || !isset($data["Common"])) {
http_response_code(400);
exit("Invalid JSON data.");
}
$siteid = $data["siteid"] ?? null;
$pingbackkey = $data["pingbackkey"] ?? null;
foreach ($data["Common"] as $entry) {
$mappedData = [];
foreach ($entry as $subEntry) {
$mappedData = array_merge($mappedData, $subEntry);
}
$voterIP = $mappedData["ip"] ?? null;
$success = abs((int)($mappedData["success"] ?? 1));
$reason = $mappedData["reason"] ?? null;
$pingUsername = $mappedData["pb_name"] ?? null;
processEntry($voterIP, $success, $reason, $pingUsername, $pingbackkey);
}
http_response_code(200);
exit("JSON data processed successfully.");
} else {
// Handle POST Data
$voterIP = $_POST["VoterIP"] ?? null;
$success = abs((int)($_POST["Successful"] ?? 1));
$reason = $_POST["Reason"] ?? null;
$pingUsername = $_POST["pingUsername"] ?? null;
$pingbackkey = $_POST["pingbackkey"] ?? null;
processEntry($voterIP, $success, $reason, $pingUsername, $pingbackkey);
http_response_code(200);
exit("POST data processed successfully.");
}
function processEntry($voterIP, $success, $reason, $pingUsername, $pingbackkey) {
if ($pingbackkey !== "ENTER-YOUR-PINGBACKKEY-HERE") {
http_response_code(403);
exit("Invalid pingback key.");
}
$link = mysqli_connect("localhost", "user", "password", "db");
if (!$link) {
http_response_code(500);
exit("Database connection error.");
}
$query = "SELECT Username FROM UserTbl WHERE username = ?";
$stmt = mysqli_prepare($link, $query);
if ($stmt) {
mysqli_stmt_bind_param($stmt, "s", $pingUsername);
if (mysqli_stmt_execute($stmt)) {
$result = mysqli_stmt_get_result($stmt);
if ($row = mysqli_fetch_assoc($result)) {
if ($success == 0) {
// send reward to $row["Username"]
}
// Optionally log reason here
} else {
// No user found
}
mysqli_free_result($result);
} else {
http_response_code(500);
exit("Failed to execute the query.");
}
mysqli_stmt_close($stmt);
} else {
http_response_code(500);
exit("Failed to prepare the SQL query.");
}
mysqli_close($link);
}