Új hozzászólás Aktív témák

  • kadam4

    tag

    válasz Forza_JUVE #6889 üzenetére

    Nem tudom miért nem jelenik meg a kép, de leírom, hogy én hogyan csináltam Captcha kódot.
    Kiír egy 6 karakterből álló random kódot, a kódot az inputoknál a code_check-be írja be, a captcha_code-ba pedig te írod majd be.
    Küldés után pedig, ezt a kettőt kell összehasonlítani, hogy megegyeznek e, ha igen, akkor beíródik a szöveg, ha meg nem, akkor dobjon egy hibaüzenetet.
    Ehhez be kell kapcsolni a php_gd2-t, hogy megjelenjen majd a kép(lehet a tiédnél is be kell).

    Kód:

    <?php

    $capt="";
    $text=array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
    // Karakterek generálása
    $texta=$text[rand('0','25')];
    $textb=$text[rand('0','25')];
    $textc=$text[rand('0','25')];
    $textd=$text[rand('0','25')];
    $texte=$text[rand('0','25')];
    $textf=$text[rand('0','25')];
    //Egybe a 6 karakter
    $capt=$texta.$textb.$textc.$textd.$texte.$textf;

    $im = @ imagecreate ( 90 , 30 );// 90*30-as kép generálása
    $background_color = imagecolorallocate ( $im , 255, 255, 0 );//háttérszín
    $text_color = imagecolorallocate ( $im , rand('0','255') , rand('0','255') , rand('0','255') );//szöveg színe (random)
    $border = imagecolorallocate( $im, 255, 0, 0 );

    imagettftext ( $im , 15 , 2 , 10 , 20 , $text_color , "ttf.ttf" , $texta ); //méret szög xstart ystart szin ttf text
    imagettftext ( $im , 15 , 0 , 22 , 20 , $text_color , "ttf.ttf" , $textb );
    imagettftext ( $im , 15 , 20 , 37 , 20 , $text_color , "ttf.ttf" , $textc);
    imagettftext ( $im , 15 , 0 , 49 , 20 , $text_color , "ttf.ttf" , $textd );
    imagettftext ( $im , 15 , 0 , 61 , 20 , $text_color , "ttf.ttf" , $texte );
    imagettftext ( $im , 15 , 0 , 70 , 20 , $text_color , "ttf.ttf" , $textf );
    imagepng ( $im, 'captcha.png' );
    imagedestroy ( $im );

    // képet ne cashelje a browser
    $cachekiller = time();

    // kiíratás
    echo "
    <form method='post' action='sajat link'>
    <b>Kód:</b><br><img src='captcha.png?{$cachekiller}' alt='' align='absmiddle'>
    <input type='hidden' name='code_check' value='$capt' />
    <input type='text' name='captcha_code' value='' size='10' maxlength='6'><br>
    <input type='submit' value='Küld'></form>";
    ?>

Új hozzászólás Aktív témák