Visualizzazione dei risultati da 1 a 9 su 9
  1. #1
    Utente di HTML.it
    Registrato dal
    Aug 2004
    Messaggi
    376

    Creare immagine captcha

    Io ho questo codice:

    Pagina sess.php:
    codice:
    <?php
    
    session_start();
    
    function randomkeys($lenght) {
    
      $key = NULL;
    
      $pattern = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";  
    
        for ($i=0;$i<$lenght;$i++) {
    
            $key .= $pattern{rand(0,61)};
    
        }
    
        return $key;
    
    }
    
    $_SESSION['chiave'] = randomkeys(8);
    
    ?>
    
    [img]img.php[/img]
    Pagina img.php:
    codice:
    <?php
    
    if (isset($_SESSION['chiave'])) {
    
      header("Content-type: image/png");
    
      $string = $_SESSION['chiave'];
    
      $img = imagecreatefrompng("bg.png");
    
      $color = imagecolorallocate($img, 0, 90, 60);
    
      imagestring($img, rand(4,5), 15, 10, $string, $orange);
    
      imagepng($img);
    
      imagedestroy($img);
    
    }
    ?>
    E poi ho la bg.png nella stessa directory.
    Dovrebbe creare un'immagine random, ma nonostante il mio web server abbia le GD abilitate non vedo nessuna immagine: come mai?

  2. #2
    Utente di HTML.it
    Registrato dal
    Dec 2006
    Messaggi
    34
    Premetto (quasi) totale ignoranza in materia,
    ma non potrebbe essere per questo:


    [...]
    $img = imagecreatefrompng("bg.png");
    $color = imagecolorallocate($im, 0, 90, 60);
    imagestring($im, rand(4,5), 15, 10, $string, $orange);
    imagepng($im);
    imagedestroy($im);
    [...]


    usi $img nel primo caso e $im in tutti gli altri...

  3. #3
    Utente di HTML.it
    Registrato dal
    Aug 2004
    Messaggi
    376
    e quello l'ho corretto: però continuo a non vedere nulla

  4. #4

    ............

    Ciao.
    devi mettere $_SESSION['chiave']
    nel file img.php e session_start()
    in tutte e due le pagine.
    Solitamente IE ha dei problemi con imagepng
    prova con imagejpeg.


    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  5. #5
    Utente di HTML.it
    Registrato dal
    Aug 2004
    Messaggi
    376
    non ho capito.
    Ho esattamente le due pagine come nel primo post, con l'aggiunta si session_start nell'altra pagina.

    Se sposto $_SESSION['chiave'] = randomkeys(8); nel file img.php ho l'errore "call to undefined function ecc "

    e sto usando Firefox

  6. #6

    ........

    Codice PHP:
    // devi mettere il font nella stessa dir dello script
    $im imagecreatefromjpeg($imgname); /* Attempt to open */
    $grey imagecolorallocate($im128128128);
    $font 'arial.ttf';
    // Add some shadow to the text
    imagettftext($im2001121$grey$font$string); 
    Una cosa del genere.
    Devi mettere la generazione della stringa in img.php.

    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  7. #7
    Codice PHP:
    <?php
    session_start
    ();

    if (isset(
    $_SESSION['chiave'])) {

      
    header("Content-type: image/png");

      
    $string $_SESSION['chiave'];

      
    $img imagecreatefrompng("bg.png");

      
    $color imagecolorallocate($img09060);

      
    imagestring($imgrand(4,5), 1510$string$color);

      
    imagepng($img);

      
    imagedestroy($img);

    }
    ?>
    I'm the solution
    http://www.mishacattaneo.ch/
    I'm fifteen. Scusate le domande ripetitive.

  8. #8
    Utente di HTML.it
    Registrato dal
    Aug 2004
    Messaggi
    376
    per whisher: non ho un font .ttf da inserire, vorrei poter far tutto senza font (mi basta quello di sistema): si può?

    per mcthepirate: alla fine così ho fatto, ma non vedo l'immagine

  9. #9

    .............

    C:\WINDOWS\Fonts\ARIAL.TTF
    Si puo fare anche attraverso un immagine del font
    per esempio o attraverso i font gdf ma è
    alquanto complicato da gestire.
    Su phpclasses trovi delle classi che utilizzano
    questo metodo.


    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

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.