すでに述べたように、偶然にも、ImageMagick- MagickWand for PHPへのインターフェースに精通する必要がありました 。 結局のところ、ライブラリは非常に強力で興味深いものです。
さて、実験として、また将来のために、このライブラリを使用してキャプチャを生成するための関数を作成しました。 その利点は、ディスクに画像を書き込む必要がないため、削除する必要がないことです。 いわば、その場ですべてが起こります。
それは私が得たものです
最初のフォームと検証:
<?php
if ($_POST['submitbutton'] === 'ok') { // , . ,
if (md5($_POST['check']) != $_POST['str']) { // $_POST['check'] - , . $_POST['str'] -
echo 'FALSE'; //
}
else {
echo 'TRUE'; //
}
}
function get_random_string($leight) //
{
$ret="";
for ($i=0; $i<$leight; $i++)
{
if ( mt_rand(1,2) == 1 )
$char_code=mt_rand(48,57);
else
$char_code=mt_rand(97,122);
$ret.=chr($char_code);
}
return $ret;
}
session_start(); // ,
$rand_string = get_random_string(5); // 5
$_SESSION['capt'] = $rand_string; //
$capt = '<img src="capcha.php" />'; // ,
$str = md5($rand_string); // -
echo $capt; //
?>
<!-- --> <form action="test.php" method="post"> <input type="text" name="check" /> <input type="hidden" name="str" value="<?php echo $str; ?>" /> <button name="submitbutton" type="submit" value="ok"></button>
<?php
if ($_POST['submitbutton'] === 'ok') { // , . ,
if (md5($_POST['check']) != $_POST['str']) { // $_POST['check'] - , . $_POST['str'] -
echo 'FALSE'; //
}
else {
echo 'TRUE'; //
}
}
function get_random_string($leight) //
{
$ret="";
for ($i=0; $i<$leight; $i++)
{
if ( mt_rand(1,2) == 1 )
$char_code=mt_rand(48,57);
else
$char_code=mt_rand(97,122);
$ret.=chr($char_code);
}
return $ret;
}
session_start(); // ,
$rand_string = get_random_string(5); // 5
$_SESSION['capt'] = $rand_string; //
$capt = '<img src="capcha.php" />'; // ,
$str = md5($rand_string); // -
echo $capt; //
?>
<!-- --> <form action="test.php" method="post"> <input type="text" name="check" /> <input type="hidden" name="str" value="<?php echo $str; ?>" /> <button name="submitbutton" type="submit" value="ok"></button>
<?php
if ($_POST['submitbutton'] === 'ok') { // , . ,
if (md5($_POST['check']) != $_POST['str']) { // $_POST['check'] - , . $_POST['str'] -
echo 'FALSE'; //
}
else {
echo 'TRUE'; //
}
}
function get_random_string($leight) //
{
$ret="";
for ($i=0; $i<$leight; $i++)
{
if ( mt_rand(1,2) == 1 )
$char_code=mt_rand(48,57);
else
$char_code=mt_rand(97,122);
$ret.=chr($char_code);
}
return $ret;
}
session_start(); // ,
$rand_string = get_random_string(5); // 5
$_SESSION['capt'] = $rand_string; //
$capt = '<img src="capcha.php" />'; // ,
$str = md5($rand_string); // -
echo $capt; //
?>
<!-- --> <form action="test.php" method="post"> <input type="text" name="check" /> <input type="hidden" name="str" value="<?php echo $str; ?>" /> <button name="submitbutton" type="submit" value="ok"></button>
<?php
if ($_POST['submitbutton'] === 'ok') { // , . ,
if (md5($_POST['check']) != $_POST['str']) { // $_POST['check'] - , . $_POST['str'] -
echo 'FALSE'; //
}
else {
echo 'TRUE'; //
}
}
function get_random_string($leight) //
{
$ret="";
for ($i=0; $i<$leight; $i++)
{
if ( mt_rand(1,2) == 1 )
$char_code=mt_rand(48,57);
else
$char_code=mt_rand(97,122);
$ret.=chr($char_code);
}
return $ret;
}
session_start(); // ,
$rand_string = get_random_string(5); // 5
$_SESSION['capt'] = $rand_string; //
$capt = '<img src="capcha.php" />'; // ,
$str = md5($rand_string); // -
echo $capt; //
?>
<!-- --> <form action="test.php" method="post"> <input type="text" name="check" /> <input type="hidden" name="str" value="<?php echo $str; ?>" /> <button name="submitbutton" type="submit" value="ok"></button>
今すぐ直接画像ジェネレータ
<?php
session_start(); //
$secret = $_SESSION['capt']; // , -
$color = '#d67f25'; //
$background = NewMagickWand(); // Magicwand -
MagickNewImage($background,200,75,$color); //
MagickSetImageFormat($background, 'png'); // - png
MagickAddNoiseImage($background,MW_ImpulseNoise); //
$drawing=NewDrawingWand(); // -
DrawSetFont($drawing,"ACADEROM.TTF"); //
DrawSetFontSize($drawing,48); //
DrawSetGravity($drawing,MW_SouthWestGravity); // .
for ($i = 1; $i <= 5; $i++) { 1 . - 5
$r_st = substr($secret,($i-1),1); //
$angle_mod = rand(0,45); //
$angle_polar = rand(0,1); // , ,
if ($angle_polar == 1) { //
$angle = $angle_mod;
}
else { // -
$angle = '-'.$angle_mod;
}
$letter_color_1 = dechex(rand(0,255)); // .
$letter_color_2 = dechex(rand(0,255));
$letter_color_3 = dechex(rand(0,255));
$letter_color = '#'.$letter_color_1.$letter_color_2.$letter_color_3; //
$fontcolor_light=NewPixelWand(); // MagickWand .
PixelSetColor($fontcolor_light,"#000000"); // -
DrawSetFillColor($drawing,$fontcolor_light); //
MagickAnnotateImage($background,$drawing,($i*30),0,$angle,$r_st); //
$fontcolor_light=NewPixelWand(); // ,
PixelSetColor($fontcolor_light,"$letter_color"); //
DrawSetFillColor($drawing,$fontcolor_light); //
MagickAnnotateImage($background,$drawing,($i*30),1,$angle,$r_st); //
}
header('Content-type: image/jpeg');
MagickEchoImageBlob($background); //
?>
したがって、最初のスクリプトの実行中に、ランダムな文字列を生成します。この文字列は、画像ジェネレーターに$ _SESSIONグローバル配列に与えます。この配列は、この文字列を既に解析し、ランダムな角度とランダムな色で文字/数字を描画します。
そして今、私は専門家に質問があります!
このキャプチャはどれくらい安定していますか? どうにかして簡単に移動できますか? どういうわけか不可能だと思いますが、いつものように、私はそれを疑います...