test
This commit is contained in:
+22
-19
@@ -1,22 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
$gif_files = glob($_SERVER['DOCUMENT_ROOT'] . '/assets/gifs/*.gif');
|
// ============================================================
|
||||||
$gif_files = array_values($gif_files);
|
// FILE 1: /gif/index.php
|
||||||
|
// Visited when someone pastes sistav.com/gif into Discord
|
||||||
// If a specific GIF was requested via ?id=, serve its embed
|
// ============================================================
|
||||||
if (isset($_GET['id'])) {
|
|
||||||
$id = (int)$_GET['id'];
|
|
||||||
$gif = isset($gif_files[$id])
|
|
||||||
? '/assets/gifs/' . basename($gif_files[$id])
|
|
||||||
: '';
|
|
||||||
|
|
||||||
|
$token = bin2hex(random_bytes(8));
|
||||||
$base_url = 'https://sistav.com';
|
$base_url = 'https://sistav.com';
|
||||||
$gif_url = $base_url . $gif;
|
$gif_url = $base_url . '/assets/gif.php?t=' . $token;
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta property="og:type" content="website">
|
<meta property="og:type" content="website">
|
||||||
<meta property="og:url" content="<?= $base_url ?>/gif?id=<?= $id ?>">
|
<meta property="og:url" content="<?= $base_url ?>/gif">
|
||||||
<meta property="og:image" content="<?= htmlspecialchars($gif_url) ?>">
|
<meta property="og:image" content="<?= htmlspecialchars($gif_url) ?>">
|
||||||
<meta property="og:image:type" content="image/gif">
|
<meta property="og:image:type" content="image/gif">
|
||||||
<meta name="twitter:card" content="summary_large_image">
|
<meta name="twitter:card" content="summary_large_image">
|
||||||
@@ -25,13 +21,20 @@ if (isset($_GET['id'])) {
|
|||||||
</head>
|
</head>
|
||||||
<body></body>
|
<body></body>
|
||||||
</html>
|
</html>
|
||||||
<?php
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// No ?id= — pick a random GIF and redirect to its unique URL
|
<?php
|
||||||
// The random token makes the URL unique so Discord won't serve a cached embed
|
// ============================================================
|
||||||
$id = array_rand($gif_files);
|
// FILE 2: /assets/gif.php
|
||||||
$token = bin2hex(random_bytes(4)); // e.g. ?id=3&t=a1b2c3d4
|
// Streams a random GIF — t= token is ignored, just busts cache
|
||||||
header("Location: /gif?id={$id}&t={$token}");
|
// ============================================================
|
||||||
|
|
||||||
|
$gif_files = glob(__DIR__ . '/gifs/*.gif');
|
||||||
|
if (empty($gif_files)) { http_response_code(404); exit; }
|
||||||
|
|
||||||
|
$file = $gif_files[array_rand($gif_files)];
|
||||||
|
|
||||||
|
header('Content-Type: image/gif');
|
||||||
|
header('Content-Length: ' . filesize($file));
|
||||||
|
header('Cache-Control: no-store');
|
||||||
|
readfile($file);
|
||||||
exit;
|
exit;
|
||||||
Reference in New Issue
Block a user