CONNEXION
  • RetourJeux
    • Sorties
    • Hit Parade
    • Les + populaires
    • Les + attendus
    • Soluces
    • Tous les Jeux
    • Gaming
  • RetourActu Gaming
    • News
    • Astuces
    • Tests
    • Previews
    • Toute l'actu gaming
  • RetourBons plans
    • Bons plans
    • Bons plans Smartphone
    • Bons plans Hardware
    • Bons plans Image et Son
    • Bons plans Amazon
    • Bons plans Cdiscount
    • Bons plans Decathlon
    • Bons plans Fnac
    • Tous les Bons plans
  • RetourJVTech
    • Actus High-Tech
    • Intelligence Artificielle
    • Smartphones
    • Mobilité urbaine
    • Hardware
    • Image et son
    • Tutoriels
    • Tests produits High-Tech
    • Guides d'achat High-Tech
    • JVTech
  • RetourCulture
    • Actus Culture
    • Culture
  • RetourVidéos
    • A la une
    • Gaming Live
    • Vidéos Tests
    • Vidéos Previews
    • Gameplay
    • Trailers
    • Chroniques
    • Replay Web TV
    • Toutes les vidéos
  • RetourForums
    • Hardware PC
    • PS5
    • Switch 2
    • Xbox Series
    • Switch
    • Pokemon pocket
    • FC 25 Ultimate Team
    • League of Legends
    • Tous les Forums
  • PC
  • PS5
  • Xbox Series
  • Switch 2
  • PS4
  • One
  • Switch
  • iOS
  • Android
  • MMO
  • RPG
  • FPS
En ce moment Genshin Impact Valhalla Breath of the wild Animal Crossing GTA 5 Red dead 2
Liste des sujets

[HTML] et [PHP] captcha

pktupuducul2
pktupuducul2
Niveau 5
03 avril 2012 à 19:29:28

Ca m'afficehe une icone d'image qui n'exitse pas voici le code de image.php :

<?php

include 'captcha.php';

/*
* Préparation des paramètres
*/

if( is_array($captcha['font_file']) )
$captcha['font_file'] = $captcha['font_file'][ rand(0,count($captcha['font_file'])-1) ];
$captcha['font_file'] = font_path($captcha['font_file']);
$captcha['nb_char'] = rand($captcha['nb_char_min'], $captcha['nb_char_max']);
$captcha['font_color'] = convert_color($captcha['font_color']);
$captcha['background_color'] = convert_color($captcha['background_color']);
$captcha['border_color'] = convert_color($captcha['border_color']);

/*
* Génération du code
*/

$code = '';
for($i=0; $i<$captcha['nb_char']; $i++)
{
$char = $captcha['char_list'][ rand(0,strlen($captcha['char_list'])-1) ];
if( !strstr($code, $char) ) $code .= $char;
else $i--;
}
if( !$captcha['casse_sensitive'] ) $code = strtoupper($code);
$_SESSION['captcha_code'] = md5($code);

/*
* Génération de l'image
*/

$image = imageCreate($captcha['width'], $captcha['height']);
$background_color = imageColorAllocate(
$image,
$captcha['background_color']['R'],
$captcha['background_color']['G'],
$captcha['background_color']['B']
);

$last_x = 5;
for($i=0; $i<strlen($code) ; $i++)
{
$font_color = color_variation($captcha['font_color'], $captcha['font_color_variation']);

$size = rand($captcha['font_size_min'], $captcha['font_size_max']);
$angle = $captcha['rotation'] - rand(0, 2*$captcha['rotation']);
$x = $last_x;
$last_x += $size+5;
$y = $captcha['height']-($captcha['height']-$size)/2;
$font_color = imageColorAllocate(
$image,
$font_color['R'],
$font_color['G'],
$font_color['B']
);
$char = $code[$i];

imagettftext(
$image,
$size,
$angle,
$x,
$y,
$font_color,
$captcha['font_file'],
$char
);
}

$decallage = ($captcha['width']-$last_x)/2;

// On centre le texte
$image2 = imageCreate($captcha['width'], $captcha['height']);
$background_color = imageColorAllocate(
$image2,
$captcha['background_color']['R'],
$captcha['background_color']['G'],
$captcha['background_color']['B']
);
imagecopy(
$image2,
$image,
$decallage,
0,
0,
0,
$captcha['width'],
$captcha['height']
);

/*
* Affichage de l'image
*/

header('Content-type: image/jpeg');
header('Cache-Control: no-store, no-cache, must-revalidate');

imagejpeg($image2,'',$captcha['quality']);
imageDestroy($image);
imageDestroy($image2);

/*
* Diverses fonctions utiles
*/

function convert_color($hexcolor)
{
$hexcolor = ltrim($hexcolor, '#');
$color['R'] = hexdec(substr($hexcolor,0,2));
$color['G'] = hexdec(substr($hexcolor,2,2));
$color['B'] = hexdec(substr($hexcolor,4,2));
return $color;
}

function color_variation($color, $variation)
{
if( is_array($color) )
{
$color['R'] = color_variation($color['R'], $variation);
$color['G'] = color_variation($color['G'], $variation);
$color['B'] = color_variation($color['B'], $variation);
}
else
{
$v = $variation - rand(0, 2*$variation);
$color += $v;
if($color<0) $color = 0;
if($color>255) $color = 255;
}
return $color;
}

function font_path($font_file)
{

return realpath('./fonts') . ((ereg('/',realpath('./fonts')))?'/':'\\') . $font_file;
}

?>

et de captcha.php : <?php

/*
* Tiny Captcha
* Réalisé par seebz - http://seebz.be
*
* Source et documentation :
* http://seebz.be/blog/38-tiny-captcha-un-captcha-anti-spam-leger-et-personnalisable.html
*
*/

/*
* Configuration
*/

$captcha['width'] = 80;
$captcha['height'] = 20;

$captcha['font_file'] = 'luggerbu.ttf';
$captcha['font_color'] = '000000';
$captcha['font_color_variation'] = 150;
$captcha['font_size_min'] = 11;
$captcha['font_size_max'] = 13;

$captcha['background_color'] = 'ffffff';

$captcha['char_list'] = 'BCDJKLMNPRTWXY389';

$captcha['nb_char_min'] = 4;
$captcha['nb_char_max'] = 4;

$captcha['rotation'] = 20;
$captcha['quality'] = 70;
$captcha['casse_sensitive'] = false;

/*
* Initialisation
*/

if( session_id()== ) @session_start();
$captcha['basepath'] =
str_replace($_SERVER['DOCUMENT_ROOT'],
,str_repla
ce('\\','/',dirname(__FILE__)))."/";

/*
* Diverses fonctions utiles
*/

function captcha_image()
{
global $captcha;
echo '<img src="' , $captcha['basepath'] , 'image.php" id="tinycaptchaimg" />';
}

function captcha_field()
{
global $captcha;
if( !$captcha['casse_sensitive'] )
$style = 'style="text-transform:uppercase"';

echo <<< FIELD
<input type="text" name="tinycaptcha" maxlength="{$captcha['nb_char_max']}" size="{$captcha['nb_char_max']}" {$style} />
FIELD;
}

function captcha_refresh()
{
global $captcha;
$html = '<img src="' . $captcha['basepath'] . 'refresh.png" alt="Refresh" />';

echo <<< REFRESH
<span
onclick="document.getElementById('tinycaptchaimg')
.src='{$captcha['basepath']}image.php?'+Math.round
(Math.random(0)*1000);" style="cursor:pointer">{$html}</span>
REFRESH;
}

function captcha_verif($code=false)
{
global $captcha;
if( !$code )
$code = $_POST['tinycaptcha'];
if( !$captcha['casse_sensitive'] )
$code = strtoupper($code);
return md5($code)==$_SESSION['captcha_code'];
}

?>

bob63
bob63
Niveau 11
03 avril 2012 à 22:06:46

Là comme ca j'ai pas le temps de tout regarder.

Mais tu sais en PHP, une simple addition du genre "Combien font 7 + 7" et si la personne met pas 14 tu dis que le captcha est mauvais. Un robot ne trouvera pas la bonne réponse (tu peux complexifier le truc".

Je regarderais le code si tu tiens vraiment à ta méthode ...

Sous forums
  • Aide à l'achat Mac
  • Steam Deck
  • Création de sites web
  • Création de Jeux
  • Linux
  • Programmation
  • Internet
  • Macintosh
  • Hardware
La vidéo du moment