A php killer game implementation
at master 828 B view raw
1<?php 2session_start(); 3 4require_once 'priv/errorhandler.php'; 5require_once 'priv/pdo.php'; 6 7if(!isset($_SESSION['qr']['id'])) 8{ 9 header('Location: login.php'); 10 die(); 11} 12 13header('Location: game.php'); 14 15$sql = " 16SELECT qr_events_id 17FROM qr_players 18WHERE qr_events_id = (SELECT id FROM qr_events WHERE end_date > NOW() ORDER BY start_date DESC LIMIT 1) 19AND qr_users_id = ? 20"; 21$id = DB::prepare($sql)->texecute([$_SESSION['qr']['id']])->fetch(); 22if($id) 23{ 24 die(); 25} 26 27$secret = substr(str_shuffle('ABCDEFGHIJKLMNOPQRSTUVW'), 0, 5); 28$sql = ' 29INSERT INTO qr_players 30(qr_events_id, qr_users_id, secret) VALUES 31((SELECT id FROM qr_events WHERE end_date > NOW() ORDER BY start_date DESC LIMIT 1), ?, ?) 32ON DUPLICATE KEY UPDATE secret = CONCAT(secret, \'X\') 33'; 34DB::prepare($sql)->texecute([$_SESSION['qr']['id'], $secret]);