protected function validateCampaignCode($code) { if (ends_with($code, '.png')) { $this->trackingMode = true; $code = substr($code, 0, -4); } $parts = explode('!', base64_decode($code)); if (count($parts) < 3) { throw new ApplicationException('Invalid code'); } list($campaignId, $subscriberId, $hash) = $parts; /* * Render unique content for the subscriber */ $this->campaign = Message::find((int) $campaignId); $this->subscriber = $this->campaign->subscribers()->where('id', (int) $subscriberId)->first(); if (!$this->subscriber) { $this->subscriber = Subscriber::find((int) $subscriberId); } if (!$this->campaign || !$this->subscriber) { throw new ApplicationException('Invalid code'); } /* * Verify unique hash */ $verifyValue = $campaignId . '!' . $subscriberId; $verifyHash = md5($verifyValue . '!' . $this->subscriber->email); if ($hash != $verifyHash) { throw new ApplicationException('Invalid hash'); } }