-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsteam.php
More file actions
138 lines (114 loc) · 5.38 KB
/
steam.php
File metadata and controls
138 lines (114 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Meine Steam-Spiele</title>
<style>
body { font-family: Arial, sans-serif; background: #121212; color: #eee; padding: 20px; }
h2 { margin-top: 40px; }
ul { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 15px; }
li { background: #1e1e1e; padding: 10px; border-radius: 8px; display: flex; align-items: center; width: 220px; }
img { width: 50px; height: 50px; margin-right: 10px; border-radius: 4px; }
.game-info { display: flex; flex-direction: column; }
.game-name { font-weight: bold; }
.playtime { font-size: 0.9em; color: #aaa; }
</style>
</head>
<form method="post">
Steam-ID: <input type="text" name="steamid">
<input type="submit" value="Senden">
</form>
<body>
<?php
$steamApiKey = '';
if (isset($_POST['steamid'])) {
$steamId = $_POST['steamid']; // Wert in Variable speichern
$profileUrl = "https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key={$steamApiKey}&steamids={$steamId}";
$profileData = json_decode(@file_get_contents($profileUrl), true);
$player = $profileData['response']['players'][0] ?? null;
if ($player) {
$avatar = $player['avatarfull'] ?? '';
$name = $player['personaname'] ?? 'Unbekannt';
echo "<h2>Profil von {$name}</h2>";
if ($avatar) {
echo "<img src='{$avatar}' alt='{$name}' class='avatar'>";
}
} else {
echo "<p>Profil nicht gefunden oder privat.</p>";
}
// helper: baut die steam-community image-url
function steam_image_url($appid, $hash) {
return $hash ? "https://media.steampowered.com/steamcommunity/public/images/apps/{$appid}/{$hash}.jpg" : null;
}
// helper: prüft, ob URL existiert (HEAD)
function url_exists($url) {
$headers = @get_headers($url);
return is_array($headers) && preg_match('#HTTP/\d+\.\d+\s+2\d\d#', $headers[0] ?? '');
}
// fallback: holt header image aus Store API
function store_header_image($appid) {
$json = @file_get_contents("https://store.steampowered.com/api/appdetails?appids={$appid}&l=de");
if (!$json) return null;
$data = json_decode($json, true);
if (!isset($data[$appid]['success']) || !$data[$appid]['success']) return null;
return $data[$appid]['data']['header_image'] ?? null;
}
// rendert ein Game-Item (Name + Bild + Zeit)
function render_game_li($appid, $name, $hash, $altHours = '') {
$img = steam_image_url($appid, $hash);
if (!$img || !url_exists($img)) {
// versuch icon hash (falls hash war logo). $hash kann beides sein, aber wir prüfen nochmal nichts gefunden -> store header
$storeHeader = store_header_image($appid);
$img = $storeHeader ?: 'https://via.placeholder.com/150?text=No+Image';
}
$hours = $altHours !== '' ? " - $altHours h" : '';
echo "<li><img src=\"" . htmlspecialchars($img) . "\" alt=\"" . htmlspecialchars($name) . "\" /><div class='game-info'><span class='game-name'>" . htmlspecialchars($name) . "</span><span class='playtime'>{$hours}</span></div></li>";
}
// --- Zuletzt gespielt ---
$recentUrl = "https://api.steampowered.com/IPlayerService/GetRecentlyPlayedGames/v1/?key={$steamApiKey}&steamid={$steamId}&count=7";
$recentJson = @file_get_contents($recentUrl);
$recentData = $recentJson ? json_decode($recentJson, true) : null;
echo "<h2>Zuletzt gespielt</h2><ul>";
if (!empty($recentData['response']['games'])) {
foreach ($recentData['response']['games'] as $game) {
$name = $game['name'] ?? 'Unbekannt';
$playtime = isset($game['playtime_2weeks']) ? round($game['playtime_2weeks']/60,1) : '';
// img_logo_url kann leer sein — nutze img_logo_url oder img_icon_url
$hash = $game['img_logo_url'] ?? ($game['img_icon_url'] ?? null);
render_game_li($game['appid'], $name, $hash, $playtime);
}
} else {
echo "<li>Keine Daten (Profil evtl. privat oder Fehler)</li>";
}
echo "</ul>";
// --- Meistgespielt ---
$ownedUrl = "https://api.steampowered.com/IPlayerService/GetOwnedGames/v1/?key={$steamApiKey}&steamid={$steamId}&include_appinfo=1&include_played_free_games=1";
$ownedJson = @file_get_contents($ownedUrl);
$ownedData = $ownedJson ? json_decode($ownedJson, true) : null;
$games = $ownedData['response']['games'] ?? [];
usort($games, fn($a,$b) => ($b['playtime_forever'] ?? 0) <=> ($a['playtime_forever'] ?? 0));
echo "<h2>Meistgespielt</h2><ul>";
foreach (array_slice($games, 0, 7) as $game) {
$name = $game['name'] ?? 'Unbekannt';
$playtime = isset($game['playtime_forever']) ? round($game['playtime_forever']/60,1) : '';
$hash = $game['img_logo_url'] ?? ($game['img_icon_url'] ?? null);
render_game_li($game['appid'], $name, $hash, $playtime);
}
echo "</ul>";
$ownedUrl = "https://api.steampowered.com/IPlayerService/GetOwnedGames/v1/?key={$steamApiKey}&steamid={$steamId}&include_played_free_games=1";
$ownedData = json_decode(file_get_contents($ownedUrl), true);
$totalMinutes = 0;
if (!empty($ownedData['response']['games'])) {
foreach ($ownedData['response']['games'] as $game) {
$totalMinutes += $game['playtime_forever'] ?? 0; // Minuten
}
}
$totalHours = round($totalMinutes / 60, 1);
$totalHoursOutput = "Insgesamt gespielt: {$totalHours} Stunden";
echo "<h2>$totalHoursOutput</h2>";
} else {
echo "<h1>Gebe die Steam-ID an</h1>";
}
?>
</body>
</html>