Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jul 2006
    Posts
    399
    Thanks
    33
    Thanked 7 Times in 7 Posts

    including captcha

    hi
    i need to include a captcha in a form, the code is a simple captcha wich goes on like this:
    PHP Code:
    <?php
    session_start
    ();

    //Now lets use md5 to generate a totally random string
    $md5 md5(microtime() * mktime());

    /*
    We dont need a 32 character long string so we trim it down to 5
    */
    $string substr($md5,0,5);


    /*
    Now for the GD stuff, for ease of use lets create
     the image from a background image.
    */

    $captcha imagecreatefrompng("./CAPTCHA.png");

    /*
    Lets set the colours, the colour $line is used to generate lines.
     Using a blue misty colours. The colour codes are in RGB
    */

    $black imagecolorallocate($captcha,22136175);
    $line imagecolorallocate($captcha,233,239,239);;

    /*
    Now to make it a little bit harder for any bots to break,
    assuming they can break it so far. Lets add some lines
    in (static lines) to attempt to make the bots life a little harder
    */
    imageline($captcha,0,0,39,29,$line);
    imageline($captcha,40,0,64,29,$line);

    /*
    Now for the all important writing of the randomly generated string to the image.
    */
    imagestring($captcha52010$string$black);


    /*
    Encrypt and store the key inside of a session
    */

    $_SESSION['key'] = md5($string);

    /*
    Output the image
    */
    header("Content-type: image/png");
    imagepng($captcha);

      
    ?>
    it works when i test it on a single page but when i include it on my web page i have a problem with the headers already sent stuff:
    Code:
    <label for="saisir_code">
    Veuillez saisir le code <SUP class="oblig">*</SUP><br>
    <input type="text" name="saisir_code" id="saisir_code" class="text">
    </label>
    </td>
    <td style="padding-left: 100px">
    <?php
    
    $md5 = md5(microtime() * mktime());
    $string = substr($md5,0,5);
    $captcha = imagecreatefrompng("includes/images/CAPTCHA.png");
    
    $black = imagecolorallocate($captcha,221, 36, 175);
    $line = imagecolorallocate($captcha,233,239,239);;
    imageline($captcha,0,0,39,29,$line);
    imageline($captcha,40,0,64,29,$line);
    imagestring($captcha, 5, 20, 10, $string, $black);
    header("Content-type: image/png");
    imagepng($captcha);
    
    ?>
    </td>
    <td>
    </td>
    </tr>
    
    <tr>
    so i get this alreday sent headers error , i cannot see how to place the imagepng($captcha); code because if i put it on top of page the whole page will be a png.



    Code:
    Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\xampp\htdocs\my\www3\includes\_top.php:23) in C:\Program Files\xampp\htdocs\my\www3\includes\_myin.php on line 222
    ‰PNG  IHDR‹ _cAPLTE$RˆIDAT8A ^xd˜hœKq=”؍SgEc4Re[ZRn/#4‡—€MJ”-‹„‘00P62–‘9_krS$L@&‡]A#“"“wO;dAMLY}Nš™š. CA‡[OŒ&Ntu:y@Xl4'zv[jW/f2b[fN\}1sJŒvvdUo/mŒ$6IENDB`‚
    Last edited by sybil6; 06-16-2010 at 04:28 PM.

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Are you a Help Vampire?

  • #3
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    I should also have included this text from the tutorial you likely followed:
    Then you just display the image to the user with a simple <img xsrc="captcha.php" border="0"> tag.
    Are you a Help Vampire?

  • #4
    Regular Coder
    Join Date
    Jul 2006
    Posts
    399
    Thanks
    33
    Thanked 7 Times in 7 Posts
    hi, thanks for your reply, so i also put the header("Content-type: image/png"); in the imaege.php file?
    regards.

  • #5
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    That's right, because that's the content you want delivered as an image.
    Are you a Help Vampire?

  • Users who have thanked tomws for this post:

    sybil6 (06-16-2010)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •