oop - prevent session initialization in incomplete php object -
i'm using mvc pattren , start sessions in construct of controller class . class (expect core's one) loaded spl_autoload_register(). create ajax class that's subclass of controller in order prevent user executing multiple ajax request in short interval of time use following code
class ajax extends controller { public function __construct() { parent::__construct(false); if ($this->checkattempts()) exit(); } public function checkattempts() { $counter = 0; $attempts = session::get(ajax); $attempts = ($attempts === false) ? [] : $attempts; if ($attempts === false) session::set(ajax, []); else $this->setattempt(); foreach ($attempts $key => $attempt) { if (time() - intval($attempt) <= 10) $counter++; else session::destroyarray(ajax, $key); } return $counter >= 5; } public function setattempt() { return session::setarray(ajax, time()); } //ajax methods ... }
the problem when open controller such home (haven't construct)
class home extends controller { public function index(){...} }
the script initialize sessions in checkattepmt method of ajax class mean method checkattepmt called , session set eg when echo nothing appear !
when print session variable in home controller found session set in ajax controller exists ( clear them in each test ) .
i used debug_backtrace() figure out problem
class ajax extends controller { public function __construct() { parent::__construct(false); $_session['trace'] = debug_backtrace(); } }
the result is
[trace] => array ( [0] => array ( [file] => d:\__path__\application\core\application.php [line] => 24 [function] => __construct [class] => ajax [object] => __php_incomplete_class object ( [__php_incomplete_class_name] => ajax ) [type] => -> [args] => array ( ) ) [1] => array ( [file] => d:\__path__\public\index.php [line] => 15 [function] => __construct [class] => application [object] => application object ( [controller:protected] => __php_incomplete_class object ( [__php_incomplete_class_name] => ajax ) [method:protected] => getconfirmmsg [params:protected] => array ( ) ) [type] => -> [args] => array ( ) )
what's relation between __php_incomplete_class , problem , how slove ?
i found out problem ! there's jquery ajax requersts fired before click event happen fix .
Comments
Post a Comment