gregwar / captcha Goto Github PK
View Code? Open in Web Editor NEWPHP Captcha library
License: MIT License
PHP Captcha library
License: MIT License
Hello:
I use this package in two pros,same codes, both are laravel frameworks. But only one can display the picture. I hope you can help me.Thank you in advance for your kind help and I am looking forward to your answer.
When a picture generated uses uppercase letters, ->getPhrase()
returns a lowercase phrase.
Variables should be renamed, some comments added and some things like distortion factorized
Hello,
I get the following error
FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught Error: Call to undefined method Gregwar\Captcha\PhraseBuilder::doNiceisze() in /Captcha/src/Gregwar/Captcha/PhraseBuilder.php:57
cani Putting captcha field and captcha renew link at the same row ??
And how can i change the term "renew" to an icon??
I already removed the "0" and the "O" from the charset because of confusion
We should add the "niceize" logic to the phrasebuilder, which would ignore the case and be nice with characters that look likes (1, l and I, O and 0 etc.)
Hello Guys!!!
I see there is an error in php 7.4 version with Call to undefined function Gregwar\Captcha\imagejpeg()
this error is coming up on line number 565 in below file vendor/gregwar/captcha/src/Gregwar/Captcha/CaptchaBuilder.php
Can you please see it and fix it !!!
Thanks
what`s question for this?
thanks!
Before I submit a pull request, just want to make sure whether it's necessary.
With usage of capture, we also need save the phrase to validate user input. Usually we may use session or a cache component. Well, if we choose to use cache, we also need a cache key for each capture. Thanks to the fingerprint
property, we can simply use md5(json_encode($captcha->getFingerprint()))
or md5(implode('', $captcha->getFingerprint()))
to generate an unique key as the cache key.
As mentioned above, whether it's better to add an accessory function called getToken()
, just like this:
public function getToken()
{
if (empty($this->getFingerprint())) {
throw new \Exception('Captcha token can only be accessed after built');
}
return md5(implode('', $this->getFingerprint()));
}
Hi. Pls help for this subject.
GIF can increase the difficulty of recognition.
$builder = new CaptchaBuilder();
$builder->build(215,80);
$builder->setBackgroundColor(0,0,0);
$builder->setIgnoreAllEffects(false);
$code=$builder->getPhrase();
header("Cache-Control: no-cache, must-revalidate");
header('Content-Type: image/jpeg');
$builder->output();
ping @jeremylivingston
Convert all your functions to static if you want the examples to be correct like that one: $phrase = \Gregwar\Captcha\PhraseBuilder::build(5, '0123456789');
or,
define constructor, build object and call member function: $phrase = new \Gregwar\Captcha\PhraseBuilder()->build(5, '0123456789');
Hi
I'm tring to put the text_color parameter in the form definition as the follow exemple:
$builder->
add(...)
...
->add('captcha', 'captcha', array('text_color' => array(255,0,0) ))
...
But seems that it takes only the global config in the config.yml :
....
gregwar_captcha:
width: 100
height: 50
quality: 20
background_color: [255, 255, 255]
text_color: [255, 0, 0]
...
Can you check please ?
Thanx
Andrea
Can individual letters use different colors?
Can you use other background confusion? Confused as small letters?
E.g:
https://www.php.cn/captcha.html
$captcha = new CaptchaBuilder('12345');
var_dump($captcha->getPhrase()); // 12345
var_dump($captcha->inline());exit; // error: imagejpeg() expects parameter 1 to be resource, null given
ErrorException: count(): Parameter must be an array or an object that implements Countable in C:\OpenServer\domains\site.dev\vendor\gregwar\captcha\CaptchaBuilder.php:333
I'm using PHP 7.2 RC2
Hello guys
Autoload installed via composer... all is well. I also created a temp directory, writable in the same directory where the files of captcha are.
The result is a blank image :-(
The code is
$builder = new CaptchaBuilder;
$builder->build();
echo "<pre>"; print_r($builder); echo "</pre>"; exit;
header('Content-type: image/jpeg');
$builder->output();
exit;
When i uncomment the line starting with "echo", i get a blank image and the result of the print_r (the echo line) is as follows:
What am I doing wrong?
Gregwar\Captcha\CaptchaBuilder Object
(
[fingerprint:protected] => Array
(
[0] => 0
[1] => 207
[2] => 221
[3] => 228
[4] => 2
[5] => 253
[6] => 155
[7] => 239
[8] => 0
[9] => 26
[10] => 20
[11] => 97
[12] => 32
[13] => 3
[14] => 240
[15] => 154
[16] => 163
[17] => 1
[18] => 14
[19] => 39
[20] => 145
[21] => 9
[22] => 2
[23] => 1
[24] => 61
[25] => 56
[26] => 69
[27] => 8
[28] => 5
[29] => -3
[30] => 2
[31] => 0
[32] => 0
[33] => 4
[34] => 2
[35] => -6
[36] => -4
[37] => 3
[38] => 0
[39] => 4
[40] => 1
[41] => 77
[42] => 37
[43] => 3
[44] => 0
[45] => 107
[46] => 14
[47] => 45
[48] => 29
[49] => 3
[50] => 1
[51] => 65
[52] => 19
[53] => 79
[54] => 13
[55] => 1
[56] => 121
[57] => 28
[58] => 7
[59] => 46
[60] => 0
[61] => 0
[62] => -6
[63] => 3
)
[useFingerprint:protected] =>
[textColor:protected] => Array
(
)
[backgroundColor:protected] =>
[backgroundImages:protected] => Array
(
)
[contents:protected] => Resource id #3
[phrase:protected] => 3jfj9
[builder:protected] => Gregwar\Captcha\PhraseBuilder Object
(
[length] => 5
[charset] => abcdefghijklmnpqrstuvwxyz123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
)
[distortion:protected] => 1
[maxFrontLines:protected] =>
[maxBehindLines:protected] =>
[maxAngle:protected] => 8
[maxOffset:protected] => 5
[interpolation:protected] => 1
[ignoreAllEffects:protected] =>
[allowedBackgroundImageTypes:protected] => Array
(
[0] => image/png
[1] => image/jpeg
[2] => image/gif
)
[tempDir] => temp/
[background] => 13622756
)
Hi have a look please on this site http://cyberparc.org/ hope you can tell me why the captcha picture does not show up, thank you for help.
Hi, thanks for developing this library.
I want to tell you that I've made an extension for Yii framework based on this library. Here is the repository yii2-captcha. I hope you like it.
If there are any problem please file an issue in that repository.
Thank you.
Hello, I have recently begun to see some of that's just such a message in the log
2015/06/08 15:41:56 [error] 23082
0: *8471087 FastCGI sent in stderr: "PHP message: PHP Warning: Division by zero in /var/www/vendor/gregwar/captcha/CaptchaBuilder.php on line 321"
request: "GET /_gcb/generate-captcha/gcb_captcha?n=1433767309?1589940139 HTTP/1.1",
VERSION v1.1
Thank you!
Hi!
I'm trying to implement this module, but after having downloaded it with composer, when I add 'Gregwar\Captcha\CaptchaBuilder' to providers on any app page I get an error:
Call to undefined method Gregwar\Captcha\CaptchaBuilder::isDeferred
without acutally adding any other code.
Maybe you can help with this?
I have a form, on submit button click, with AJAX I am calling the php that sends the mail and once the email is sent the form refreshes, how can I generate a new captcha once the form is sent?
In v1.1.7, getPhrase() will only return string in lower-case,
while in v1.1.8, getPhrase() will return upper&lower characters.
if there is a notice in README, it'll be better to prevent someone get confused after doing composer update
Why sometimes the characters of getPhrase () and the characters in inline () are inconsistent, not all are wrong, but the case of one of the letters is inconsistent.
E.g:
The image base64 from inline () is processed in the browser, and the result displayed is YF7B
But the result of getPhrase () is Yf7B
why? Is it a browser issue or a code design issue?
Is there anything that prevents it from working with Finder 2.8?
I am using this package through gregwar/captcha-bundle
, which will work with Symfony 2.8. However, gregwar/captcha
requires Finder 3.0 or above. As the result, I get gregwar/captcha v1.1.3
which is not compatible with PHP 7, while Symfony 2.8 is.
Method:$builder->save('out.jpg');
or <img src="<?php echo $builder->inline(); ?>" />
no problem
The problem is that:
header('Content-type: image/jpeg');
$builder->output();
After output,inline it directly in the HTML page。
Directly nested this page in the IMG label:
<img name="randomImage" id="randomImage" src="http://test.com/login/captcha/1" title="Refresh" size="10">
The following is the code:
$phrase= new PhraseBuilder;
$code= $phrase->build(4);
$builder = new CaptchaBuilder($code, $phrase);;
$builder->setBackgroundColor(255, 255, 255);
$builder->build($width = 80, $height = 38, $font = null);
$phrase = $builder->getPhrase();
Session::flash('logincaptcha', `$phrase);`
header("Cache-Control: no-cache, must-revalidate");
header('Content-Type: image/jpeg');
$builder->output();
I added in 00ac9a5 a file named ocr.php
which will try to guess the captcha contents using ocrad
I have about 1.5% of success right now, this number is too much and should really be 0
like the title
if (empty($this->backgroundImages)) {
// if background images list is not set, use a color fill as a background
$image = imagecreatetruecolor($width, $height);
if ($this->backgroundColor == null) {
$bg = imagecolorallocate($image, $this->rand(200, 255), $this->rand(200, 255), $this->rand(200, 255));
} else {
$color = $this->backgroundColor;
$bg = imagecolorallocate($image, $color[0], $color[1], $color[2]);
}
$this->background = $bg;
imagefill($image, 0, 0, $bg);
} else {
// use a random background image
$randomBackgroundImage = $this->backgroundImages[rand(0, count($this->backgroundImages)-1)];
$imageType = $this->validateBackgroundImage($randomBackgroundImage);
$image = $this->createBackgroundImageFromType($randomBackgroundImage, $imageType);
}
code in this part,if set background imaes,variable $bg will not be defined!
hi man, php 7.2 version ,CaptchBuilder 333 line, count(null) has warning ,i know error_reporting setting ,but wish you fix this bug.
你好,我在php 7.2 版本使用这个组件,但是出现了错误警告,导致不能生成验证码,我知道可以定义 error_report 错误级别忽略,但是本着严谨的态度来说,希望可以修正这个错误。
This class feels so bloated.
Can you split it up?
I installed via composer
build(); header('Content-type: image/jpeg'); $builder->output(); On IE , in the console, i see DOM7009: Unable to decode image at URL: '<>' with MIME: 'image/jpeg'. In firefox, in the main browser window, i see "the image <<>> cannot be displayed as it contains errors If i remove the header line, i do see a lot of junk chars and a jpeg header being sent out. So it does look like i have the relevant libraries for PHP installed $my_dir is outside my web directory, but i don't think that should matter, right? Thanks in advance for any help!!!!We should write at least a little readme for this
php version 7.2
in vendor/gregwar/captcha/CaptchaBuilder.php at line 333
Hello,
I'm using Captcha, and I have noticed that sometimes the code i.e ABIDE will be built as ABJDE in image.
Do you have any idea why is that mistake happened by Captcha builder->build()?
I tried captcha as explained in readme file but it doesn't work
<?php
require_once 'vendor/autoload.php';
session_start();
use Gregwar\Captcha\CaptchaBuilder;
$builder = new CaptchaBuilder;
$builder->buildAgainstOCR(); // Also tried with build() method
if (!empty($_POST['submit'])) {
$user_input = $_POST['captcha'];
if ($builder->testPhrase($user_input)) {
echo "OK!";
} else {
echo "Wrong answer";
}
}
?>
<!doctype html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<img src="<?= $builder->inline(); ?>" alt="">
<form action="captcha-test.php" method="post">
<label for="captcha">Enter Text: </label>
<input name="captcha" id="captcha">
<input type="submit" name="submit" value="OK">
</form>
</body>
</html>
1.php version 7.3.8 with gd extension active
2.$builder->getPhrase(); can get the captche value
3. $builder->output() get the 500 error , only numbers display,
I have no idea what exactly causes this, but some times when testing, I notice that when I fill in the image correctly, I have an error saying that it's invalid.
The $expectedCode
isn't equal to $form->getData()
and mostly happens after testing the same form a couple of times. I can only fix this with a hard page reload or a manual press on "renew". The return is not null, it's an actual different code than show in the image.
My configuration:
gregwar_captcha:
quality: 100
distortion: false
height: 65
width: 270
reload: true
as_url: true
interpolation: true
background_color: [255, 255, 255]
how to get captcha with transparent background?
My server can't use composer...
Can it be separate to single file?
Hello.
I have the bundle already working in Symfony2.0 (having installed the 2.0 version of the bundle).
It is apparently working fine, except for a simple question.
When I type a wrong captcha, just to test the behavior and give a proper message, I am finding that the form doesn't gives any error.
When I do
$process = $formHandler->process($confirmationEnabled);
I get a FALSE, so the form won't succeed. Tat is correct, as I typed wrongly the captcha text.
Nevertheless, after that, when I try to catch the given error
$errors = $form->getErrors();
I am getting an empty array, and so no message is coming and no message is being shown in the visual layer. I don't think that is the normal behavior.
But the weirdest part comes now:
When I inspect the form, I get no errors. That might be expected because $form->getErrors() returned an empty array, as I said before. But when I inspect the form children, I clearly can see how the captcha child HAS the error indeed. Again, this is expected, because the captcha is avoiding the form to be successfully processed. But the question is: How do I get the "internal child" error I got in the captcha child?
Attaching two images. One with the "no errors" father form. And the other with de error captcha child.
Thank you in advance!!
\gregwar\captcha\CaptchaBuilder.php
33 line
protected $textColor = [];
/**
* @var array
*/
protected $backgroundColor = [];
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.