Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Template Name: Like Sending Tool
- */
- ?>
- <?php
- session_start();
- // Database connection details (replace with your credentials)
- $host = 'localhost';
- $dbname = 'u495250137_Like_Test';
- $username = 'u495250137_Like_Test';
- $password = 'Xhn606029@';
- // Initialize error message
- $error = null;
- $result = null;
- $uid = '';
- // Attempt to connect to the database
- try {
- $pdo = new PDO( "mysql:host=$host;dbname=$dbname", $username, $password );
- $pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
- } catch ( PDOException $e ) {
- die( 'Database connection failed: ' . $e->getMessage() );
- }
- // API URLs
- $apiUrls = array(
- 'https://smartclowngameshop.vercel.app/like?uid={uid}&server_name=ind15&key=3519567351',
- 'https://smartclowngameshop.vercel.app/like?uid={uid}&server_name=ind16&key=3519567351',
- 'https://smartclowngameshop.vercel.app/like?uid={uid}&server_name=ind17&key=3519567351',
- );
- // Max requests per API per day
- $maxRequestsPerApi = 30;
- // Define the reset time (4:00 AM)
- $resetHour = 4;
- // Handle Form Submission
- if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
- $uid = htmlspecialchars( $_POST['uid'] ?? '' );
- if ( empty( $uid ) ) {
- $error = 'UID is required.';
- } else {
- // Get the current time and calculate the reset window
- $currentTime = new DateTime();
- $startOfDay = ( new DateTime() )->setTime( $resetHour, 0, 0 );
- if ( $currentTime < $startOfDay ) {
- $startOfDay->modify( '-1 day' );
- }
- $endOfDay = ( clone $startOfDay )->modify( '+1 day' );
- // Iterate over the APIs and check their usage
- foreach ( $apiUrls as $index => $apiUrl ) {
- // Check the usage count for the current API within the reset window
- $stmt = $pdo->prepare(
- 'SELECT COUNT(*) as usage_count FROM api_usage WHERE api_url = :api_url AND request_time >= :start_of_day AND request_time < :end_of_day'
- );
- $stmt->execute(
- array(
- 'api_url' => $apiUrl,
- 'start_of_day' => $startOfDay->format( 'Y-m-d H:i:s' ),
- 'end_of_day' => $endOfDay->format( 'Y-m-d H:i:s' ),
- )
- );
- $usage = $stmt->fetch( PDO::FETCH_ASSOC );
- if ( $usage['usage_count'] < $maxRequestsPerApi ) {
- // Use this API
- $apiEndpoint = str_replace( '{uid}', $uid, $apiUrl );
- // Send API request
- $response = file_get_contents( $apiEndpoint );
- if ( $response === false ) {
- $error = 'Failed to connect to the API.';
- } else {
- // Store the API request details in the database
- try {
- $stmt = $pdo->prepare( 'INSERT INTO `api_usage` (api_url, request_time) VALUES (:api_url, NOW())' );
- $stmt->execute( array( 'api_url' => $apiUrl ) );
- } catch ( PDOException $e ) {
- $error = 'Failed to record the API usage in the database: ' . $e->getMessage();
- }
- // Decode API response
- $result = json_decode( $response, true );
- // Redirect to avoid form resubmission and preserve result
- header( 'Location: ?success=1' );
- $_SESSION['api_result'] = $result;
- exit;
- }
- }
- }
- if ( ! $result && ! $error ) {
- $error = 'All APIs have reached their daily limit.';
- }
- }
- }
- // Fetch the API usage details from the database for the current reset window
- try {
- $currentTime = new DateTime();
- $startOfDay = ( new DateTime() )->setTime( $resetHour, 0, 0 );
- if ( $currentTime < $startOfDay ) {
- $startOfDay->modify( '-1 day' );
- }
- $endOfDay = ( clone $startOfDay )->modify( '+1 day' );
- $stmt = $pdo->prepare(
- 'SELECT api_url, COUNT(*) AS usage_count FROM api_usage WHERE request_time >= :start_of_day AND request_time < :end_of_day GROUP BY api_url'
- );
- $stmt->execute(
- array(
- 'start_of_day' => $startOfDay->format( 'Y-m-d H:i:s' ),
- 'end_of_day' => $endOfDay->format( 'Y-m-d H:i:s' ),
- )
- );
- $apiUsage = $stmt->fetchAll( PDO::FETCH_ASSOC );
- } catch ( PDOException $e ) {
- $error = 'Error fetching API usage: ' . $e->getMessage();
- }
- if ( isset( $_SESSION['api_result'] ) ) {
- $result = $_SESSION['api_result'];
- unset( $_SESSION['api_result'] );
- }
- ?>
- <?php
- get_header();
- the_post();
- $single = new \JNews\Single\SinglePage();
- ?>
- <div class="jeg_main <?php $single->main_class(); ?>">
- <div class="jeg_container">
- <div class="jeg_content jeg_singlepage">
- <div class="container">
- <div class="row">
- <div class="jeg_main_content col-md-8">
- <div class="entry-header">
- </div>
- <div class="entry-content">
- <div class="content-inner">
- <h1>Like Sending Tool</h1>
- <form method="POST">
- <label for="uid">Enter UID:</label>
- <input type="text" name="uid" id="uid" value="<?php echo htmlspecialchars( $uid ); ?>" required>
- <button type="submit">Send Likes</button>
- </form>
- <?php if ( isset( $_GET['success'] ) && $_GET['success'] == 1 ) : ?>
- <p>Status of Your Request:</p>
- <?php if ( $result ) : ?>
- <div style="background-color: #f9f9f9; padding: 10px; border-radius: 4px; font-family: monospace;">
- <?php
- echo "╭ Player's Nickname: " . htmlspecialchars( $result['PlayerNickname'] ) . '<br>';
- echo "├ Player's Uid: " . htmlspecialchars( $result['UID'] ) . '<br>';
- echo '├ Likes before Sent: ' . htmlspecialchars( $result['LikesbeforeCommand'] ) . '<br>';
- echo '├ Likes after Sent: ' . htmlspecialchars( $result['LikesafterCommand'] ) . '<br>';
- echo '╰ Likes Given: ' . htmlspecialchars( $result['LikesGivenByAPI'] ) . '<br>';
- ?>
- </div>
- <?php endif; ?>
- <?php elseif ( $error ) : ?>
- <p style="color: red;"><?php echo $error; ?></p>
- <?php endif; ?>
- <h2>API Usage:</h2>
- <ul>
- <?php
- $apiDisplay = array(
- 'https://smartclowngameshop.vercel.app/like?uid={uid}&server_name=ind15&key=3519567351' => 'API 1',
- 'https://smartclowngameshop.vercel.app/like?uid={uid}&server_name=ind16&key=3519567351' => 'API 2',
- 'https://smartclowngameshop.vercel.app/like?uid={uid}&server_name=ind17&key=3519567351' => 'API 3',
- );
- foreach ( $apiDisplay as $apiUrl => $apiName ) {
- $count = 0;
- foreach ( $apiUsage as $usage ) {
- if ( $usage['api_url'] === $apiUrl ) {
- $count = $usage['usage_count'];
- }
- }
- echo "<li>{$apiName}: {$count} requests</li>";
- }
- ?>
- </ul>
- </div>
- </div>
- <?php
- if ( comments_open() || '0' != jnews_get_comments_number() ) {
- comments_template();
- }
- get_template_part( 'fragment/post/author-box' );
- ?>
- </div>
- <?php
- set_query_var(
- 'sidebar',
- array(
- 'content-sidebar' => 'default-sidebar',
- 'is_sticky' => 'jeg_sticky_sidebar',
- 'sticky-sidebar' => 'jeg_sticky_sidebar',
- 'width-sidebar' => 4,
- 'position-sidebar' => 'left',
- )
- );
- get_template_part( 'fragment/archive-sidebar' );
- ?>
- </div>
- </div>
- </div>
- <?php do_action( 'jnews_after_main' ); ?>
- </div>
- </div>
- <?php
- get_footer();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement