-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.php
More file actions
73 lines (61 loc) · 1.95 KB
/
Copy pathgame.php
File metadata and controls
73 lines (61 loc) · 1.95 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
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
$room = $_GET['room'] ?? '';
$name = $_GET['name'] ?? '';
$path = "rooms/$room.json";
if (!file_exists($path)) {
die("Room not found.");
}
$data = json_decode(file_get_contents($path), true);
// Check for expiration (optional)
if (time() - ($data['created_at'] ?? 0) > 600) {
unlink($path);
die("Room has expired.");
}
// Get question list and index
$questions = $data['questions'] ?? [];
$index = $data['question_index'] ?? 0;
$current_question = $questions[$index] ?? null;
if (!$current_question) {
echo "<h2>No more questions!</h2>";
exit;
}
// ✅ Prevent early access to round
if (!($data['round_started'] ?? false)) {
echo "<h2>Waiting for the host to start the round...</h2>";
echo "<script>
setTimeout(() => {
window.location.reload();
}, 1000); // Reload every second to check for round start
</script>";
exit;
}
$players = $data['players'];
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Most Likely To - Question</title>
</head>
<body>
<h2>Question:</h2>
<p><?= htmlspecialchars($current_question) ?></p>
<form action="vote.php" method="POST">
<input type="hidden" name="room" value="<?= htmlspecialchars($room) ?>">
<input type="hidden" name="name" value="<?= htmlspecialchars($name) ?>">
<input type="hidden" name="question" value="<?= htmlspecialchars($current_question) ?>">
<p>Vote for the player you think fits best:</p>
<?php foreach ($players as $player): ?>
<label>
<input type="radio" name="vote" value="<?= htmlspecialchars($player) ?>" required>
<?= htmlspecialchars($player) ?>
</label><br>
<?php endforeach; ?>
<br>
<button type="submit">Submit Vote</button>
</form>
</body>
</html>