Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Captcha allowed on same page #2

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
14 changes: 5 additions & 9 deletions src/SimpleCaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ class SimpleCaptcha{
private $num2;
private $actionNumber;
private $arr;
private $sessionKey = '_simple_captcha';


private function generate()
{
Expand Down Expand Up @@ -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'];
}
}
4 changes: 2 additions & 2 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function getCaptchaQuestion(){
}

function getCaptchaBox($inputBoxName="_answer"){
$html= '<div style="display: flex;align-items: center;font-weight: 600;"><div>'.SimpleCaptcha::getQuestion().'</div>';
$html= '<div style="display: flex;align-items: center;font-weight: 600;"><div>'.SimpleCaptcha::getQuestion($inputBoxName).'</div>';
$html .='<div style="margin-left:10px"><input name="'.$inputBoxName.'" type="number" style="width:60px"></div></div>';
return $html;
}
}