Skip to content

Instantly share code, notes, and snippets.

@artlung
Created February 22, 2024 01:40
Show Gist options
  • Save artlung/6d61ff5522ed19afd46a6a603606260f to your computer and use it in GitHub Desktop.
Save artlung/6d61ff5522ed19afd46a6a603606260f to your computer and use it in GitHub Desktop.
Server Side Image Map for tilde.club
<?php
$defaultLink = 'https://tilde.club/~harper/link.html?action=join';
$links = [
'left' => [
'url' => 'https://tilde.club/~harper/link.html?action=join',
'x1' => 0,
'y1' => 0,
'x2' => 129,
'y2' => 75,
'text' => 'Join'
],
'middle' => [
'url' => 'https://tilde.club/~harper/link.html?action=random',
'x1' => 130,
'y1' => 0,
'x2' => 417,
'y2' => 75,
'text' => 'Random'
],
'right' => [
'url' => 'https://tilde.club/~harper/link.html?action=join',
'x1' => 418,
'y1' => 0,
'x2' => 549,
'y2' => 75,
'text' => 'Join'
]];
$validX = false;
$validY = false;
foreach ($_GET as $key => $value) {
if (preg_match('/^(\d+),(\d+)$/', $key, $matches)) {
$validX = $matches[1];
$validY = $matches[2];
}
}
if (!$validX || !$validY) {
header("Location: $defaultLink");
exit;
}
foreach ($links as $link) {
if ($validX >= $link['x1'] && $validX <= $link['x2'] && $validY >= $link['y1'] && $validY <= $link['y2']) {
header("Location: {$link['url']}");
exit;
}
}
header("Location: $defaultLink");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment