Merge pull request #1 from OpzekerIT/init

Init
This commit is contained in:
OpzekerIT 2023-09-21 09:28:25 +02:00 committed by GitHub
commit 90fd9e788c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 399 additions and 1 deletions

3
.htaccess Normal file
View file

@ -0,0 +1,3 @@
<Files config.php>
deny from all
</Files>

View file

@ -1 +1,49 @@
# pubg
\`\`\`markdown
# DTCH - PUBG Clan User Stats
This project displays the user statistics for members of the DTCH PUBG Clan.
## Features
1. Display lifetime stats for a specific game mode (solo, duo, squad).
2. Select a player from the DTCH clan and view their stats.
3. Display the PUBG API rate limit headers.
## Prerequisites
- PHP 7.4 or higher
- cURL extension for PHP
## Installation
1. Clone this repository:
\`\`\`bash
git clone [repository-url]
\`\`\`
2. Navigate to the project directory:
\`\`\`bash
cd [project-directory]
\`\`\`
3. Update the `config/config.php` file with the appropriate API key and clan members.
4. Host the project on a PHP server (like Apache).
5. Access the `user_stats.php` in your browser to view the stats.
## Usage
1. Select a game mode to view stats (solo, duo, squad).
2. Choose a clan member to view their specific stats.
3. The rate limit headers for the PUBG API are displayed at the top.
## Notes
- Ensure that the API key is kept confidential and not exposed to the public.
- The project comes with a rate limiter (`ratelimiter.php`), which can be included to restrict the frequency of page access.
## License
This project is open-source. Feel free to modify and distribute as per your needs.
\`\`\`

60
clan_stats.php Normal file
View file

@ -0,0 +1,60 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
?>
<?php //include './includes/ratelimiter.php'; ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DTCH - PUBG Clan - Clan Stats</title>
<link rel="stylesheet" href="./includes/styles.css">
</head>
<body>
<?php include './includes/navigation.php'; ?>
<main>
<section>
<h2>Clan Stats</h2>
<?php
include './config/config.php';
$url = "https://api.pubg.com/shards/steam/clans/$clanid";
$headers = array(
'Authorization: Bearer ' . $apiKey,
'Accept: application/vnd.api+json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
$clan = json_decode($response, true);
if (isset($clan['data']['attributes'])) {
echo "<table>";
echo "<tr><th>Attribute</th><th>Value</th></tr>";
foreach ($clan['data']['attributes'] as $key => $value) {
echo "<tr><td>" . htmlspecialchars($key) . "</td><td>" . htmlspecialchars($value) . "</td></tr>";
}
echo "</table>";
} else {
echo "<p>No clan attributes available</p>";
}
?>
</section>
</main>
<?php include './includes/footer.php'; ?>
</body>
</html>

5
config/config.php Normal file
View file

@ -0,0 +1,5 @@
<?php
$apiKey = 'YOURAPIKEYHERE';
$clanid = 'clan.d67f3a9805414aa7b78a1f122a7de776';
$clanmembers = array("Lanta01", "Petje1972", "TaGMoM","r00tger","Masistuta","RalphNorris","Jimbo_The_One");
?>

1
config/index.php Normal file
View file

@ -0,0 +1 @@
sup?

3
includes/footer.php Normal file
View file

@ -0,0 +1,3 @@
<footer>
<p>&copy; 2023 DTCH Clan. All rights reserved.</p>
</footer>

7
includes/navigation.php Normal file
View file

@ -0,0 +1,7 @@
<nav>
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="clan_stats.php">Clan Stats</a></li>
<li><a href="user_stats.php">User Stats</a></li>
</ul>
</nav>

41
includes/ratelimiter.php Normal file
View file

@ -0,0 +1,41 @@
<?php
session_start();
$allowed_refreshes = 3;
$allowed_time = 10;
if (!isset($_SESSION['access_times'])) {
$_SESSION['access_times'] = [];
}
$now = time();
$_SESSION['access_times'][] = $now;
foreach ($_SESSION['access_times'] as $key => $timestamp) {
if ($now - $timestamp > $allowed_time) {
unset($_SESSION['access_times'][$key]);
}
}
if (count($_SESSION['access_times']) > $allowed_refreshes) {
die('
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="3">
<title>RustAGHH</title>
</head>
<body>
<p>RUSTAAAGGHHHH je mag de pagina niet vaker dan ' . $allowed_refreshes . 'x per ' . $allowed_time . ' seconde refreshen. Over een paar seconde word je weet terug geleid</p>
</body>
</html>
');
}
?>

100
includes/styles.css Normal file
View file

@ -0,0 +1,100 @@
/* Reset some default styles */
body, h1, h2, p, ul, li, a {
margin: 0;
padding: 0;
text-decoration: none;
}
body {
font-family: Arial, sans-serif;
background-color: black;
color: white;
}
nav {
background-color: #333;
}
nav ul {
list-style-type: none;
padding: 0;
}
nav li {
display: inline-block;
margin-right: 10px;
}
nav li:last-child {
margin-right: 0;
}
nav a {
color: white;
padding: 10px 15px;
display: block;
}
nav a:hover {
background-color: #555;
}
header, main, footer {
max-width: 800px;
margin: 20px auto;
padding: 10px 20px;
border: 1px solid white;
}
header h1, section h2 {
border-bottom: 1px solid white;
margin-bottom: 10px;
padding-bottom: 5px;
}
footer {
text-align: center;
}
/* Responsive Styles */
@media (max-width: 600px) {
nav li {
display: block;
margin-right: 0;
}
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
table, th, td {
border: 1px solid white;
}
th, td {
padding: 10px;
text-align: left;
}
th {
background-color: #555;
}
tr:hover {
background-color: #444;
}
.discord-logo {
width: 50px; /* Reduced from 50px to 30px */
height: auto;
margin-top: 10px;
cursor: pointer;
transition: opacity 0.3s;
}
.discord-logo:hover {
opacity: 0.8;
}

30
index.php Normal file
View file

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DTCH - PUBG Clan</title>
<link rel="stylesheet" href="./includes/styles.css">
</head>
<body>
<?php include './includes/navigation.php'; ?>
<header>
<h1>Welcome to DTCH - PUBG Clan</h1>
</header>
<main>
<section>
<h2>Welcome to DTCH - PUBG Clan</h2>
<p>Join us on our Discord:</p>
<a href="https://discord.gg/wMXsB3ZmNA" target="_blank" rel="noopener noreferrer">
<img src="./media/discordlogo.png" alt="Discord Logo" class="discord-logo">
</a>
</section>
</main>
<?php include './includes/footer.php'; ?>
</body>
</html>

BIN
media/discordlogo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

3
phpinfo.php Normal file
View file

@ -0,0 +1,3 @@
<?php
phpinfo();
?>

97
user_stats.php Normal file
View file

@ -0,0 +1,97 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
?>
<?php //include './includes/ratelimiter.php'; ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DTCH - PUBG Clan - User Stats</title>
<link rel="stylesheet" href="./includes/styles.css">
</head>
<body>
<?php include './includes/navigation.php'; ?>
<main>
<section>
<h2>User Stats</h2>
<?php
include './config/config.php';
$headers = array(
'Authorization: Bearer ' . $apiKey,
'Accept: application/vnd.api+json'
);
$selected_mode = isset($_POST['game_mode']) ? $_POST['game_mode'] : 'squad';
// Form to select game mode
echo "<form method='post' action=''>
<input type='submit' name='game_mode' value='solo'>
<input type='submit' name='game_mode' value='duo'>
<input type='submit' name='game_mode' value='squad'>
</form><br>";
// Buttons for each player
echo "<form method='post' action=''>";
foreach ($clanmembers as $player) {
echo "<button type='submit' name='selected_player' value='$player'>$player</button>";
}
echo "</form><br>";
$selected_player = $_POST['selected_player'] ?? $clanmembers[0];
// Retrieve user IDs
$players_url = "https://api.pubg.com/shards/steam/players?filter[playerNames]=$selected_player";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $players_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$players_response = curl_exec($ch);
curl_close($ch);
$players_data = json_decode($players_response, true);
if (isset($players_data['data'])) {
$player = $players_data['data'][0];
$player_id = $player['id'];
$player_name = $player['attributes']['name'];
// Retrieve lifetime stats
$lifetime_url = "https://api.pubg.com/shards/steam/players/$player_id/seasons/lifetime?filter[gamepad]=false";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $lifetime_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$lifetime_response = curl_exec($ch);
curl_close($ch);
$lifetime_data = json_decode($lifetime_response, true);
if (isset($lifetime_data['data']['attributes']['gameModeStats'][$selected_mode])) {
$stats = $lifetime_data['data']['attributes']['gameModeStats'][$selected_mode];
echo "<h2>" . ucfirst($selected_mode) . " Lifetime Stats for $player_name</h2>";
echo "<table border='1'>";
echo "<tr><th>Stat Name</th><th>Value</th></tr>";
foreach ($stats as $stat_name => $stat_value) {
echo "<tr><td>$stat_name</td><td>$stat_value</td></tr>";
}
echo "</table><br>";
}
} else {
echo "No player data available.";
}
?>
</section>
</main>
<?php include './includes/footer.php'; ?>
</body>
</html>