db = $db; $this->ip = $ip; $this->boardId = $boardId; } public function getOrCreateID() { $stmt = $this->db->prepare(' SELECT anonymous_id FROM posts WHERE ip_address = ? AND board_id = ? ORDER BY created_at DESC LIMIT 1 '); $stmt->execute([$this->ip, $this->boardId]); $existingId = $stmt->fetchColumn(); if ($existingId) { return $existingId; } return $this->generateNewID(); } private function generateNewID() { return 'ID:' . sprintf('%06d', mt_rand(1, 999999)); } public function getIDForThread() { $stmt = $this->db->prepare(' SELECT anonymous_id FROM threads WHERE ip_address = ? AND board_id = ? ORDER BY created_at DESC LIMIT 1 '); $stmt->execute([$this->ip, $this->boardId]); $existingId = $stmt->fetchColumn(); if ($existingId) { return $existingId; } return $this->generateNewID(); } }