OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
3-31-025chanakya
/
creamapi
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
03/31/2025 06:36:42 AM
rwxr-xr-x
📄
api.php
1.35 KB
03/26/2025 03:48:04 AM
rw-r--r--
📄
db.php
355 bytes
03/26/2025 03:48:04 AM
rw-r--r--
📄
fetch_data.php
3.93 KB
03/26/2025 03:48:04 AM
rw-r--r--
📄
generate_token.php
1.34 KB
03/26/2025 03:48:04 AM
rw-r--r--
📄
proxy_fetch_data.php
932 bytes
03/26/2025 03:48:04 AM
rw-r--r--
📄
zfetch_data.php
1.89 KB
03/26/2025 03:48:04 AM
rw-r--r--
Editing: fetch_data.php
Close
<?php // Enable error reporting for debugging ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); // Include database connection include 'db.php'; // Set the content type to JSON header('Content-Type: application/json; charset=UTF-8'); // Retrieve API Key, Secret Key, and Action from URL parameters $api_key = isset($_GET['api_key']) ? trim($_GET['api_key']) : null; $secret_key = isset($_GET['secret_key']) ? trim($_GET['secret_key']) : null; $action = isset($_GET['action']) ? trim($_GET['action']) : null; // Validate API Key and Secret Key if (!$api_key || !$secret_key) { echo json_encode(['error' => 'API key and Secret key are required']); exit; } // If the action is 'count', fetch the total count of records if ($action === 'count') { $query = "SELECT COUNT(*) as total_count FROM api_tokens INNER JOIN user_collection ON api_tokens.user_id = user_collection.user_id WHERE api_tokens.api_token = ? AND api_tokens.access_key = ?;"; $stmt = $mysqli->prepare($query); if ($stmt === false) { echo json_encode(['error' => 'Failed to prepare SQL statement: ' . $mysqli->error]); exit; } $stmt->bind_param("ss", $api_key, $secret_key); if (!$stmt->execute()) { echo json_encode(['error' => 'Query execution failed: ' . $stmt->error]); exit; } $result = $stmt->get_result(); $row = $result->fetch_assoc(); echo json_encode(['status' => 'success', 'count' => $row['total_count']]); $stmt->close(); $mysqli->close(); exit; } // If the action is not 'count', proceed to fetch data // Set pagination and range parameters $limit = isset($_GET['limit']) ? (int)$_GET['limit'] : 20; // Default limit is 10 $offset = isset($_GET['offset']) ? (int)$_GET['offset'] : 0; // Default offset is 0 $sort_order = isset($_GET['sort_order']) && strtolower($_GET['sort_order']) === 'desc' ? 'DESC' : 'ASC'; // Default is 'ASC' // Validate limit and offset $limit = ($limit > 0) ? min($limit, 100) : 20; // Ensure limit is at least 1 and max 100 $offset = ($offset >= 0) ? $offset : 0; // Ensure offset is not negative // Prepare the SQL query to fetch user data $query = "SELECT user_collection.title, user_collection.description, user_collection.url, user_collection.date_added, user_collection.cover_img FROM api_tokens INNER JOIN user_collection ON api_tokens.user_id = user_collection.user_id WHERE api_tokens.api_token = ? AND api_tokens.access_key = ? ORDER BY user_collection.date_added $sort_order LIMIT ? OFFSET ?;"; // Prepare the statement $stmt = $mysqli->prepare($query); if ($stmt === false) { echo json_encode(['error' => 'Failed to prepare SQL statement: ' . $mysqli->error]); exit; } // Bind parameters, including limit and offset as integers $stmt->bind_param("ssii", $api_key, $secret_key, $limit, $offset); if (!$stmt->execute()) { echo json_encode(['error' => 'Query execution failed: ' . $stmt->error]); exit; } // Fetch the results $result = $stmt->get_result(); $data = []; // Check if records were returned if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $data[] = [ 'title' => $row['title'] ?? 'N/A', 'url' => $row['url'] ?? 'N/A', 'description' => $row['description'] ?? 'N/A', 'date_added' => $row['date_added'] ?? '' ]; } echo json_encode([ 'status' => 'success', 'data' => $data, 'total_records' => $result->num_rows ], JSON_UNESCAPED_UNICODE); } else { echo json_encode([ 'status' => 'success', 'data' => [], 'message' => 'No matching records found.' ]); } // Close the statement and database connection $stmt->close(); $mysqli->close();