. class Cookies { public $setup; public $secure = false; public function __construct (Setup $setup) { $this->setup = $setup; $this->domain = $setup->domain; // Remove port from domain if (mb_strpos ($this->domain, ':') !== false) { $this->domain = mb_substr ($this->domain, 0, strrpos ($this->domain, ':')); } // Transmit cookies over HTTPS if set so in Settings if ($setup->secureCookies === true) { $this->secure = !empty ($_SERVER['HTTPS']) ? true : false; } } // Set a cookie with expiration date public function set ($name, $value = '', $date = '') { $name = 'hashover-' . $name; // Use specific expiration date or the one in Settings $date = !empty ($date) ? $date : $this->setup->cookieExpiration; // Set the cookie if cookies are enabled if ($this->setup->setsCookies !== false) { setcookie ($name, $value, $date, '/', $this->domain, $this->secure, true); } } // Set cookies for remembering state login actions public function setFailedOn ($input, $reply_to, $replied = true) { // Set success status cookie $this->set ('failed-on', $input); // Set reply cookie if ($replied === true and !empty ($reply_to)) { $this->set ('replied', $reply_to); } // Set comment text cookie $comment = $this->setup->getRequest ('comment'); // Check if comment is set if ($comment !== false) { $this->set ('comment', $comment); } } // Get cookie value public function getValue ($name, $trim = false) { $name = 'hashover-' . $name; // Check if it exists if (!empty ($_COOKIE[$name])) { $value = $_COOKIE[$name]; // Return trimmed value if told to if ($trim === true) { $value = trim ($value, " \r\n\t"); } return $value; } // If not set return null return null; } // Expire a cookie public function expireCookie ($cookie) { // Set its expiration date to 1 if it exists if ($this->getValue ($cookie) !== null) { $this->set ($cookie, '', 1); } } // Expire HashOver's default cookies public function clear () { // Expire message cookie $this->expireCookie ('message'); // Expire error cookie $this->expireCookie ('error'); // Expire comment failure cookie $this->expireCookie ('failed-on'); // Expire reply failure cookie $this->expireCookie ('replied'); // Expire comment text cookie $this->expireCookie ('comment'); } }