diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 43246ad..bea0c4f 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -12,7 +12,7 @@ public function boot() { Validator::extend('simple_captcha', function($attribute, $value, $parameters) { - return $value == SimpleCaptcha::getAnswer(); + return $value == SimpleCaptcha::getAnswer($attribute); },'Invalid captcha answer'); } diff --git a/src/SimpleCaptcha.php b/src/SimpleCaptcha.php index 4583645..3d40fef 100644 --- a/src/SimpleCaptcha.php +++ b/src/SimpleCaptcha.php @@ -8,8 +8,6 @@ class SimpleCaptcha{ private $num2; private $actionNumber; private $arr; - private $sessionKey = '_simple_captcha'; - private function generate() { @@ -61,17 +59,15 @@ private function multiplication($num1, $num2) - public static function getQuestion() + public static function getQuestion($sessionKey) { - $instance = new self(); - Session::put($instance->sessionKey,$instance->generate()); + Session::put($sessionKey, $instance->generate()); - return Session::get($instance->sessionKey)['question']; + return Session::get($sessionKey)['question']; } - public static function getAnswer() + public static function getAnswer($sessionKey) { - $instance = new self(); - return Session::get($instance->sessionKey)['answer']; + return Session::get($sessionKey)['answer']; } } diff --git a/src/helpers.php b/src/helpers.php index f7fdbbe..5664ce6 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -7,7 +7,7 @@ function getCaptchaQuestion(){ } function getCaptchaBox($inputBoxName="_answer"){ - $html= '
'.SimpleCaptcha::getQuestion().'
'; + $html= '
'.SimpleCaptcha::getQuestion($inputBoxName).'
'; $html .='
'; return $html; -} \ No newline at end of file +}