mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-05 14:19:27 +00:00
Unique ID for each call to a controller
- Added constant FHC_CONTROLLER_ID to FHC_Controller - Added private property _controllerId to FHC_Controller - Added protected method setControllerId to FHC_Controller - Added protected method getControllerId to FHC_Controller
This commit is contained in:
@@ -4,6 +4,10 @@ if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class FHC_Controller extends CI_Controller
|
||||
{
|
||||
const FHC_CONTROLLER_ID = 'fhc_controller_id'; // name of the parameter used to identify uniquely a call to a controller
|
||||
|
||||
private $_controllerId; // contains the unique identifier of a call to a controller
|
||||
|
||||
/**
|
||||
* Standard construct for all the controllers, loads the authentication system
|
||||
*/
|
||||
@@ -11,6 +15,8 @@ class FHC_Controller extends CI_Controller
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->_controllerId = null; // set _controllerId as null by default
|
||||
|
||||
$this->load->helper('fhcauth');
|
||||
}
|
||||
|
||||
@@ -23,4 +29,34 @@ class FHC_Controller extends CI_Controller
|
||||
{
|
||||
$this->load->library('PhrasesLib', array($categories, $language), 'p');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the unique id for the called controller
|
||||
* NOTE: it is only working with HTTP GET request, not neeaded with POST
|
||||
* because the first call to the controller is via HTTP GET,
|
||||
* therefore a fhc_controller_id is already generated
|
||||
*/
|
||||
protected function setControllerId()
|
||||
{
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'GET')
|
||||
{
|
||||
$this->_controllerId = $this->input->get(self::FHC_CONTROLLER_ID);
|
||||
|
||||
if (!isset($this->_controllerId) || empty($this->_controllerId))
|
||||
{
|
||||
$this->_controllerId = uniqid(); // generate a unique id
|
||||
// Redirect to the same URL, but giving FHC_CONTROLLER_ID as HTTP GET parameter
|
||||
header(sprintf('Location: %s?%s=%s', $_SERVER['REQUEST_URI'], self::FHC_CONTROLLER_ID, $this->_controllerId));
|
||||
exit; // terminate immediately the execution of this controller
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of the property _controllerId
|
||||
*/
|
||||
protected function getControllerId()
|
||||
{
|
||||
return $this->_controllerId;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user