Source of file CookieTrackingIdentityFinder.php
Size: 1,419 Bytes - Last Modified: 2021-12-23T10:33:31+00:00
/var/www/docs.ssmods.com/process/src/code/identity/CookieTrackingIdentityFinder.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 | <?php class CookieTrackingIdentityFinder implements TrackingIdentityFinder { public static $cookie_name = "SSTC"; public static function set_tracking_cookie_name($name) { self::$cookie_name = $name; } public static function get_tracking_cookie_name() { return self::$cookie_name; } /** * The cookie tracker will always create an identity. If one doesn't exist, it creates the cookie and returns * a new ID for it. * @return null|void */ public function findOrCreate() { if (isset($_COOKIE[self::$cookie_name])) { $value = $_COOKIE[self::$cookie_name]; } else { // the cookie doesn't exist, so create the cookie with a value, and use that value $value = $this->generateCookieValue(); if (!SapphireTest::is_running_test()) { setcookie(self::$cookie_name, $value, time() + 60 * 60 * 24 * 90, "/"); } } $ident = TrackingIdentity::get_identity($this->getType(), $value); if (!$ident) { $ident = TrackingIdentity::create_identity($this->getType(), $value); } return $ident; } public function generateCookieValue() { $generator = new RandomGenerator(); return $generator->generateHash('sha1'); } public function getType() { return "cookie"; } } |