Visualizzazione dei risultati da 1 a 7 su 7

Discussione: modificare captcha

  1. #1

    modificare captcha

    Ciao a tutti,
    Ho trovato questo CPTCHA free su un sito.
    Questo è l’index
    Codice PHP:
    <?php session_start();
    if(isset(
    $_POST["captcha"]))
    {
        if (isset(
    $_SESSION["captcha"]) && $_SESSION["captcha"]==$_POST["captcha"])
        { 
    header("Location: salva.php");}

    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" >
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Captcha</title>
    <script type="text/javascript">
    function reloadCaptcha() {
    now = new Date();
    var capObj = document.getElementById('phoca-captcha');
    if (capObj) {
    capObj.src = capObj.src + (capObj.src.indexOf('?') > -1 ? '&' : '?') + Math.ceil(Math.random()*(now.getTime()));
    }
    }
    </script>
    <style type="text/css">
    body{font-family:sans-serif;}
    a img {border:0}
    </style>

    </head>
    <body>
    <form action="index.php" method="post" name="phoca-form" id="phoca-form">
    <table border="0">
    <tr>
    <td width="5">Title: </td>
    <td colspan="4"><input type="text" name="title" id="title" size="32" maxlength="200" style="border:1px solid #cccccc" width:"300px" value="<?php
    if(isset($title)){ print "$title"; }
    ?>" /></td>
    </tr>

    <tr>
    <td>Content: </td>
    <td colspan="4"><textarea name="testo" cols="32" rows="10" id="testo" style="border:1px solid #cccccc" ><?php
    if(isset($testo)){ print "$testo"; }
    ?></textarea>
    </td>
    </tr>

    <tr>
    <td>Image Verification: </td>

    <td width="5" align="left">[img]image.php[/img]</td>
    <td width="5" align="left"><input type="text" id="captcha" name="captcha" size="6" maxlength="6" style="border:1px solid #cccccc"/></td>

    <td width="5" align="left">[img]./images/icon-reload.gif[/img]</td>
    <td align="left"><small style="color:#fc0000;"></small></td>
    </tr>
    <tr>
    <td></td>
    <td colspan="4"><input type="submit" name="save" value="Submit" /> <input type="reset" name="reset" value="Reset" /></td>
    </tr>
    </table>
    </form>
    <hr />
    </body>
    </html>

    Questa invece è la classe che viene richiamata

    Codice PHP:

    <?php
    /*
     * @class Phoca Captcha
     * @copyright Copyright (C) Jan Pavelka [url]www.phoca.cz[/url]
     * @license [url]http://www.gnu.org/copyleft/gpl.html[/url] GNU/GPL
     */
    class PhocaCaptcha
    {
        function 
    displayCaptcha()
        {
            
    session_start();
            
    #header("Expires: Sun, 1 Jan 2000 12:00:00 GMT"); 
            #header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
            #header("Cache-Control: no-store, no-cache, must-revalidate"); 
            #header("Cache-Control: post-check=0, pre-check=0", false);
            #header("Pragma: no-cache");

            
    $rand_char PhocaCaptcha::generateRandomChar(6);
            
    $_SESSION['captcha'] = $rand_char;
            
    $rand_char_array = array (            $rand_char[0]."          ",
                                            
    "  ".$rand_char[1]."        "    ,
                                              
    "    ".$rand_char[2]."      "    ,
                                          
    "      ".$rand_char[3]."    "   ,
                                         
    "        ".$rand_char[4]."  "    ,
                                        
    "          ".$rand_char[5]);

            
    $image_name     PhocaCaptcha::getRandomImage();
            
    $image             = @ImageCreateFromJPEG('images/'.$image_name);
     
            foreach (
    $rand_char_array as $key => $value)
            {
             
    $font_color     PhocaCaptcha::getRandomFontColor();
             
    $position_x     PhocaCaptcha::getRandomPositionX();
             
    $position_y     PhocaCaptcha::getRandomPositionY();
             
    $font_size     PhocaCaptcha::getRandomFontSize();
             
             
    ImageString($image$font_size$position_x$position_y$valueImageColorAllocate ($image$font_color[0], $font_color[1], $font_color[2]));
            }
            
            
    header ('Content-type: image/jpeg');
            
    ImageJPEG($image,NULL,100);
            
    ImageDestroy($image);
        }


        function 
    generateRandomChar($string_length)
        {
            
            
    $digit = array(0,1,2,3,4,5,6,7,8,9);
            
    $lower = 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');
            
    $upper = 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');
            
            
    $char_group array_merge ($digit$lower$upper);
            
            
    srand ((double) microtime() * 1000000);
            
            
    $random_string '';
            
            for(
    $ch=0;$ch<$string_length;$ch++)
            {
                
    $char_group_start    0;
                
    $char_group_end     sizeof($char_group)-1;
                
    $random_char_group     rand($char_group_start$char_group_end);
                
    $random_string        .= $char_group[$random_char_group];
            }
            return 
    $random_string;
        }

        function 
    getRandomImage()
        {
            
    $rand     mt_rand(1,6);
            
    $image     '0'.$rand.'.jpg';
            return 
    $image;
        }

        function 
    getRandomPositionX()
        {
            
    $rand     mt_rand(2,3);
            return 
    $rand;
        }

        function 
    getRandomPositionY()
        {
            
    $rand     mt_rand(1,4);
            return 
    $rand;
        }

        function 
    getRandomFontSize()
        {
            
    $rand mt_rand(4,5);
            return 
    $rand;
        }

        function 
    getRandomFontColor()
        {
            
    $rand mt_rand(1,6);
            if (
    $rand == 1) {$font_color[0] = 10;     $font_color[1] = 0;     $font_color[2] = 0;}
            if (
    $rand == 2) {$font_color[0] = 0;     $font_color[1] = 0;     $font_color[2] = 153;}
            if (
    $rand == 3) {$font_color[0] = 0;     $font_color[1] = 102;     $font_color[2] = 0;}
            if (
    $rand == 4) {$font_color[0] = 102;     $font_color[1] = 51;     $font_color[2] = 0;}
            if (
    $rand == 5) {$font_color[0] = 163;     $font_color[1] = 0;     $font_color[2] = 0;}
            if (
    $rand == 6) {$font_color[0] = 0;     $font_color[1] = 82;     $font_color[2] = 163;}
            return 
    $font_color;
        }
    }
    ?>
    Vorrei cambiare il font dei caratteri e la grandezza.

    C’è chi mi sa dire come fare?

    Grazie

  2. #2

  3. #3
    Utente di HTML.it L'avatar di brodik
    Registrato dal
    Jan 2009
    Messaggi
    765
    per la grandezza basta che cambi la funzione

    Codice PHP:
    function getRandomFontSize()
    {
            
    $rand mt_rand(4,5);
            return 
    $rand;

    con ad esempio
    Codice PHP:
    function getRandomFontSize()
    {
            
    $rand 10// il font ha sempre grandezza 10
            
    return $rand;


    mentre per il font devi utilizzare
    imageloadfont() associata alla funzione ImageString (con imageloadfont() andrai a sostituire anche la funzione per la grandezza del font)

  4. #4
    grazie per la risposta ma purtroppo non sono riuscito a fare quello che mi hai suggerito.
    Ho messo
    $rand = 10;
    ma il carattere rimane uguare anche e lo aumento a 20 o 30, cambia solo se lo metto ad un valore più basso.
    Per quanto riguarda poi la possibilità di poter cambiare il tipo di font, non sono proprio riuscito a capire cosa fare.
    Comunque grazie

  5. #5
    Utente di HTML.it L'avatar di Ranma2
    Registrato dal
    Mar 2003
    Messaggi
    2,650
    suppongo che questo gestisce tutto

    Codice PHP:
             ImageString($image$font_size$position_x$position_y$valueImageColorAllocate ($image$font_color[0], $font_color[1], $font_color[2])); 

  6. #6
    credo di si.

  7. #7
    Utente di HTML.it L'avatar di brodik
    Registrato dal
    Jan 2009
    Messaggi
    765
    in effetti ho sbagliato io..

    con i font di default 1 è la scrittura più piccola e 5 quella più grande.. comunque leggi sul manuale .. è spiegato tutto molto bene..

    per font maggiori c'è imagettftext()

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.