| Server IP : 54.36.91.62 / Your IP : 216.73.217.112 Web Server : Apache System : Linux webm013.cluster127.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 User : coopiak ( 151928) PHP Version : 8.3.23 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/coopiak/amisdesseniors-fr/montpellier/plugins/system/nrframework/NRFramework/ |
Upload File : |
<?php
/**
* @author Tassos Marinos <info@tassos.gr>
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace Tassos\Framework;
defined('_JEXEC') or die('Restricted access');
use Joomla\CMS\Factory;
use Joomla\CMS\Crypt\Crypt;
class VisitorToken
{
/**
* Class instance
*
* @var object
*/
private static $instance;
/**
* Cookie Name
*
* @var string
*/
private $cookieName = "nrid";
/**
* Represents the maximum age of the visitor's cookie in seconds.
*
* @var Integer
*/
private $expire = 90000000;
/**
* Cookies Object
*
* @var object
*/
private $cookies;
/**
* Class constructor
*/
private function __construct()
{
$this->cookies = Factory::getApplication()->input->cookie;
$token = $this->cookies->get($this->cookieName, null);
if ($token === null)
{
$this->store($this->create());
}
}
/**
* Returns class instance
*
* @return object
*/
public static function getInstance()
{
if (is_null(self::$instance))
{
self::$instance = new self();
}
return self::$instance;
}
/**
* Get a visitor's unique token id, if a token isn't set yet one will be generated.
*
* @param boolean $forceNew If true, force a new token to be created
*
* @return string The session token
*/
public function get($forceNew = false)
{
return $this->cookies->get($this->cookieName);
}
/**
* Create a token-string
*
* @param integer $length Length of string
*
* @return string Generated token
*/
private function create($length = 8)
{
return bin2hex(Crypt::genRandomBytes($length));
}
/**
* Saves the cookie to the visitor's browser
*
* @param string $value Cookie Value
*
* @return void
*/
private function store($value)
{
$this->cookies->set($this->cookieName, $value, time() + $this->expire, '/', '', true);
}
}