Voting Postback Integration

When a user votes on your server through ArenaTop100, you can track their votes and reward them using a unique player ID. Here's a step-by-step guide on how to set up and integrate our postback system.

Step 1: Set Up the Voting URL

Include your unique player ID in the voting URL to track the votes. The URL should be in the following format:

https://arenatop100.com/details/[SiteSlug]?userId=[UniquePlayerID]
  • Replace [SiteSlug] with your site's slug from ArenaTop100.
  • Replace [UniquePlayerID] with the unique identifier you use to track your players (e.g., their username or player ID).

Example:

<a href="https://arenatop100.com/details/[SiteSlug]?userId=[UniquePlayerID]">
  <img src="https://arenatop100.com/vote-banner.webp" alt="Vote for our server!" />
</a>

Step 2: Configure Your Postback URL

In your ArenaTop100 account settings, specify the URL where we will send the postback request after a successful vote. This URL should point to a script on your server that handles the postback data. Add a long random secret key to it: your script checks the key, so only ArenaTop100 can credit votes. We never show this URL to voters.

https://yourwebsite.com/postback-handler.php?key=YOUR_SECRET_KEY

Do not filter postbacks by IP address. They are sent from cloud servers whose IP address changes, so an IP check rejects genuine postbacks.

Right after a successful vote we send one POST request with Content-Type: application/json and wait up to 10 seconds for the answer. The request body:

{
  "success": true,
  "message": "Your vote was successfully submitted!",
  "userId": "[UniquePlayerID]",
  "postbackURL": "https://yourwebsite.com/postback-handler.php?key=YOUR_SECRET_KEY",
  "timestamp": "2026-01-15T18:30:00.000Z",
  "category": "mu-online"
}

Step 3: Implement the Postback Handler

Create a PHP script on your server to handle the postback request. This script will:

  • Verify that the request comes from ArenaTop100 by checking the secret key.
  • Validate the userId received in the POST request.
  • Credit the user for voting and update their voting status.

Example PHP Code:

1<?php
2// Include database connection
3include('db_connect.php'); // Ensure this file connects to the correct database
4
5// The secret key from your postback URL on ArenaTop100, for example
6// https://yourwebsite.com/postback-handler.php?key=YOUR_SECRET_KEY
7// Use a long random value, such as the output of bin2hex(random_bytes(24)).
8// Do not check the IP address instead: postbacks come from cloud servers
9// whose IP address changes.
10$secretKey = 'YOUR_SECRET_KEY';
11
12// Check that the request comes from ArenaTop100
13$key = isset($_GET['key']) && is_string($_GET['key']) ? $_GET['key'] : '';
14if (!hash_equals($secretKey, $key)) {
15    http_response_code(403);
16    error_log("Unauthorized postback attempt from IP: " . $_SERVER['REMOTE_ADDR']);
17    echo json_encode(['success' => false, 'message' => 'Unauthorized request.']);
18    exit;
19}
20
21// Get the JSON payload from the POST request
22$input = file_get_contents("php://input");
23$data = json_decode($input, true);
24
25// Validate the input data
26if (!isset($data['success']) || !isset($data['userId'])) {
27    http_response_code(400);
28    error_log("Invalid postback request: Missing required fields.");
29    echo json_encode(['success' => false, 'message' => 'Invalid request.']);
30    exit;
31}
32
33// Assign variables from the payload
34$success = $data['success'];
35$userId = is_string($data['userId']) ? trim($data['userId']) : '';
36
37if ($userId === '') {
38    // Log invalid userId and send an error response
39    http_response_code(400);
40    error_log("Invalid postback request: missing or invalid userId.");
41    echo json_encode(['success' => false, 'message' => 'Invalid request.']);
42    exit;
43}
44
45if ($success) {
46    // Success case: The vote is valid
47    mysqli_begin_transaction($conn, MYSQLI_TRANS_START_READ_WRITE);
48
49    try {
50        // Credit the user for voting (e.g., 10 credits)
51        $creditUserQuery = "UPDATE users SET credits = credits + 10 WHERE user_id = ?";
52        $stmt = mysqli_prepare($conn, $creditUserQuery);
53        mysqli_stmt_bind_param($stmt, 's', $userId);
54        mysqli_stmt_execute($stmt);
55        mysqli_stmt_close($stmt);
56
57        // Update the voting status (if necessary)
58        $updateVoteStatusQuery = "UPDATE users SET vote = vote + 1 WHERE user_id = ?";
59        $stmt = mysqli_prepare($conn, $updateVoteStatusQuery);
60        mysqli_stmt_bind_param($stmt, 's', $userId);
61        mysqli_stmt_execute($stmt);
62        mysqli_stmt_close($stmt);
63
64        // Commit the transaction
65        mysqli_commit($conn);
66
67        // Respond to ArenaTop100 with success
68        echo json_encode([
69            'success' => true,
70            'message' => "User with userId '$userId' successfully voted and received 10 credits."
71        ]);
72    } catch (Exception $e) {
73        // Rollback the transaction on failure
74        mysqli_rollback($conn);
75        error_log("Error processing postback for userId $userId: " . $e->getMessage());
76        echo json_encode(['success' => false, 'message' => 'An error occurred.']);
77    } finally {
78        // Always close the database connection
79        mysqli_close($conn);
80    }
81} else {
82    // Failure case: The vote is invalid or user must wait
83    error_log("Vote failed for userId $userId: " . $data['message']);
84    echo json_encode([
85        'success' => false,
86        'message' => $data['message']
87    ]);
88}
89?>

How It Works

  1. User Clicks the Banner: The user clicks on the voting banner on your site, which redirects them to ArenaTop100 with their unique player ID in the URL.
  2. User Votes on ArenaTop100: The user votes for your server on ArenaTop100.
  3. Postback Request: After a successful vote, ArenaTop100 sends a POST request to your specified postback URL with the userId.
  4. Handle Postback: Your PHP script processes the postback request, validates the userId, credits the user, updates their voting status and responds with a confirmation.

By following these steps, you can seamlessly integrate ArenaTop100's voting postback system and reward your players for voting.