Results 1 to 8 of 8

Thread: Captcha, Mail2Form PHP problems

  1. #1
    Join Date
    Jul 2010
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Captcha, Mail2Form PHP problems

    I'm at the point where I might start to cause more damage than repair...been thinking about this for too long.

    I'm new to PHP so I'm at a complete loss as to what the problems are here. I'm redesigning a 'Contact' page for a website...adding a Captcha generator to it. I created the form using the Form2Mail program and inserted the Captcha Code per the instructions of the Captcha Software provider.

    The errors are as follows:

    Code:
    Warning: opendir(fonts) [function.opendir]: failed to open dir: No such file or directory in /home/content/b/r/i/brianericson/html/webdesign/html/captcha/captchac_code.php on line 29
    
    Warning: imagettfbbox() [function.imagettfbbox]: Could not find/open font in /home/content/b/r/i/brianericson/html/webdesign/html/captcha/captchac_code.php on line 61
    
    Warning: imagettfbbox() [function.imagettfbbox]: Could not find/open font in /home/content/b/r/i/brianericson/html/webdesign/html/captcha/captchac_code.php on line 61
    
    Warning: imagettfbbox() [function.imagettfbbox]: Could not find/open font in /home/content/b/r/i/brianericson/html/webdesign/html/captcha/captchac_code.php on line 61
    
    Warning: imagettfbbox() [function.imagettfbbox]: Could not find/open font in /home/content/b/r/i/brianericson/html/webdesign/html/captcha/captchac_code.php on line 61
    
    Warning: imagettfbbox() [function.imagettfbbox]: Could not find/open font in /home/content/b/r/i/brianericson/html/webdesign/html/captcha/captchac_code.php on line 61
    
    Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/content/b/r/i/brianericson/html/webdesign/html/captcha/captchac_code.php on line 220
    
    Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/content/b/r/i/brianericson/html/webdesign/html/captcha/captchac_code.php on line 220
    
    Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/content/b/r/i/brianericson/html/webdesign/html/captcha/captchac_code.php on line 220
    
    Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/content/b/r/i/brianericson/html/webdesign/html/captcha/captchac_code.php on line 220
    
    Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/content/b/r/i/brianericson/html/webdesign/html/captcha/captchac_code.php on line 220
    
    Warning: Cannot modify header information - headers already sent by (output started at /home/content/b/r/i/brianericson/html/webdesign/html/captcha/captchac_code.php:29) in /home/content/b/r/i/brianericson/html/webdesign/html/captcha/captchac_code.php on line 240
    PNG  IHDR"PLTEkf 浝y3'IDATcD"(CC uIENDB`The Captcha Code you entered is invalid. Please press the Back button of your browser and try again
    The file in question is:

    captchac_code.php
    Code:
    <?php
    
    // ----------------------------------------------------------------
    // Captcha Creator PHP Image Displaying Script.
    // Copyright (c) 2007 Alexandru Marias. All rights reserved
    // Web: http://www.captchacreator.com
    // Phone: +40722486348
    // ----------------------------------------------------------------
    
    // Define the characters that can make up the Turing string
    // Mixed-case is apparently a bit of a problem,
    // so lets pick one or the other
    
    include_once('captchac_config.php'); // Security functions
    include_once('captchac_lib.php'); // Security functions
    
    session_start();
    
    $turing = RandomCode($CMinSize,$CMaxSize);
    
    // Put it in session
    $_SESSION['turing_string'] = $turing;
                       
    switch ($captcha_type) {
    case 1:
        
    if ($CFontUsed == 1 ) {
    $i=0;
    if ($handle = opendir($fonts_dir)) 
    	{
        	while (false !== ($file = readdir($handle))) 
            	if ($file != "." && $file != "..") {
                	$fontl[$i] = $fonts_dir . '/' . $file;
    		$i++;
            	}   
    	closedir($handle);
        	}
    $FontsNo=$i;
    
    $fontno = mt_rand(0,$FontsNo-1);
    $font = $fontl[$fontno];
    }
    	else $font = $CFontURL;
                     
    /* initialize variables */
    
    $length = strlen($turing);
    $data = array();
    $image_width = $image_height = 0;
    
    
    /* build the data array of the characters, size, placement, etc. */
    
    for($i=0; $i<$length; $i++) {
    
      $char = substr($turing, $i, 1);
    
      $size = mt_rand($CFontSizeMin, $CFontSizeMax);
      $angle = mt_rand($CFontRotMin, $CFontRotMax);
    
      $bbox = ImageTTFBBox( $size, $angle, $font, $char );
    
      $char_width = max($bbox[2], $bbox[4]) - min($bbox[0], $bbox[6]);
      $char_height = max($bbox[1], $bbox[3]) - min($bbox[7], $bbox[5]);
    
      $image_width += $char_width + $CFontPadding;
      $image_height = max($image_height, $char_height);
    
      $data[] = array(
        'char'    => $char,
        'size'    => $size,
        'angle'    => $angle,
        'height'  => $char_height,
        'width'    => $char_width,
      );
    }
    
    /* calculate the final image size, adding some padding */
    
    $x_padding = 12;
    
    if ( $CSize == 1 )
    	{
    	$image_width += ($x_padding * 2);
    	$image_height = ($image_height * 1.5) + 2;
    	}
       else {
    	$image_width = $CSizeWidth;
    	$image_height = $CSizeHeight;
    	}
    
    
    /* build the image, and allocte the colors */
    
    $im = ImageCreate($image_width, $image_height);
    $cs = mt_rand(1,3);
    
    if ($CBackgroundType == 2)
    	{
    	$r = hexdec(substr($CBackgroundColor,1,2));
    	$g = hexdec(substr($CBackgroundColor,3,2));
    	$b = hexdec(substr($CBackgroundColor,5,2));
    	}
    
    else
    	{
    
    $d1 = $d2 = $d3 = 0;
    while ( ($d1<50) AND ($d2<50) AND ($d3<50) )
    	{
    	$r = mt_rand(200,255);
    	$g = mt_rand(200,255);
    	$b = mt_rand(200,255);
    
    	$d1 = abs($r-$g);
    	$d2 = abs($r-$b);
    	$d3 = abs($g-$b);
    	}
    	}
    
    $color_bg    = ImageColorAllocate($im, $r, $g, $b );
    
    $color_border  = ImageColorAllocate($im, round($r/2), round($g/2), round($b/2));
    
    $color_line0  = ImageColorAllocate($im, round($r*0.85), round($g*0.85), round($b*0.85) );
    
    $color_elipse0  = ImageColorAllocate($im, round($r*0.95), round($g*0.95), round($b*0.95) );
    $color_elipse1  = ImageColorAllocate($im, round($r*0.90), round($g*0.90), round($b*0.90) );
    
    	$d1 = mt_rand(0,50);
    	$d2 = mt_rand(0,50);
    	$d3 = mt_rand(0,50);
    
    $color_line1  = ImageColorAllocate($im, $r-$d1, $g-$d2, $b-$d3 );
    
    $d1 = $d2 = $d3 = 0;
    while ( ($d1<100) AND ($d2<100) AND (d3<100) )
    	{
    	$r = mt_rand(0,150);
    	$g = mt_rand(0,150);
    	$b = mt_rand(0,150);
    
    	$d1 = abs($r-$g);
    	$d2 = abs($r-$b);
    	$d3 = abs($g-$b);
    	}
    
    switch ( $CFontColorType ) 
    	{
    	case 1 : $color_text    = ImageColorAllocate($im, $r, $g, $b );
    		break;
    	case 2 : $color_text    = ImageColorAllocate($im, 0, 0, 0 );
    		break;
    	case 3 : $color_text    = ImageColorAllocate($im, 255, 255, 255 );
    		break;
    	case 4 : $color_text    = ImageColorAllocate($im, $color_text_r, $color_text_g, $color_text_b );
    		break;
    	}
    
    $noiset = mt_rand(1,2);
    
    if ( $CBackgroundType == 1 )
    	{
    
    switch ($noiset) {
    	case '1' :
    		/* make the random background elipses */
    	for($l=0; $l<10; $l++) {
    
      		$c = 'color_elipse' . ($l%2);
    
    		$cx = mt_rand(0, $image_width);
      		$cy = mt_rand(0, $image_width);
      		$rx = mt_rand(10, $image_width);
      		$ry = mt_rand(10, $image_width);
    
    		ImageFilledEllipse($im, $cx, $cy, $rx, $ry, $$c );
      		}; break;
    	case '2' :
    		/* make the random background lines */
    		for($l=0; $l<10; $l++) {
    
    		$c = 'color_line' . ($l%2);
    
     	  	$lx = mt_rand(0, $image_width+$image_height);
      		$lw = mt_rand(0,3);
      		if ($lx > $image_width) {
        		  $lx -= $image_width;
        		  ImageFilledRectangle($im, 0, $lx, $image_width-1, $lx+$lw, $c );
      		   } else ImageFilledRectangle($im, $lx, 0, $lx+$lw, $image_height-1, $c );
      		}; break;
    	} // end switch  
    
    	}
    
    if ( $CBackgroundType == 0 )
    	{
      	$image_data=getimagesize($CBackgroundFile);
    
      	$image_type=$image_data[2];
    
      	if($image_type==1) $img_src=imagecreatefromgif($CBackgroundFile);
      	elseif($image_type==2) $img_src=imagecreatefromjpeg($CBackgroundFile);
      	elseif($image_type==3) $img_src=imagecreatefrompng($CBackgroundFile);
    
    		if ( $CBackgroundFillType == 1 ) {
    					  imagesettile($im,$img_src);
    					  imagefill($im,0,0,IMG_COLOR_TILED);
    					}
    		else imagecopyresampled($im,$img_src,0,0,0,0,$image_width,$image_height,$image_data[0],$image_data[1]);
    	
    	}
    
    /* output each character */
    
    $pos_x = $x_padding + ($CFontPadding / 2);
    foreach($data as $d) {
    
      $pos_y = ( ( $image_height + $d['height'] ) / 2 );
      ImageTTFText($im, $d['size'], $d['angle'], $pos_x, $pos_y, $color_text, $font, $d['char'] );
    
      $pos_x += $d['width'] + $CFontPadding;
    
    }
    
    /* a nice border */
    
    ImageRectangle($im, 0, 0, $image_width-1, $image_height-1, $color_border);
    
    /* display it */
      
    switch ($output_type) {
     case 'jpeg':
      Header('Content-type: image/jpeg');
      ImageJPEG($im,NULL,100);
      break;
    
     case 'png':
     default:
      Header('Content-type: image/png');
      ImagePNG($im);
      break;
    }
    ImageDestroy($im);
    
    break;
    
    case 2:
    
    break;
    
    }
    
    session_write_close();
    
    
     ?>
    To my knowledge I have all files/directories pointed in the right direction. Research I carried out yesterday claimed that the errors I stated above were due to GoDaddy (where my site is hosted) not having FreeType and GD Library enabled. I called GoDaddy and they claim both FreeType and GD Library are in fact enabled.

    If that is true then this is where my lack of knowledge with PHP takes over. A live example of the webpage in question can be found at Contact Page.

    Any advice or feedback would be greatly appreciated.
    Last edited by Snookerman; 09-23-2010 at 05:14 PM. Reason: removed link by user request

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Config files are in the wrong locations, not sure where you have them located but you either need to change where you are calling them from or where they are located.

    404:
    404:
    Last edited by Snookerman; 09-23-2010 at 05:12 PM. Reason: removed link by user request
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Jul 2010
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    bluewalrus, captcha and HDWForm2Mail are in two different folders.


    and
    Last edited by Snookerman; 09-23-2010 at 05:13 PM. Reason: removed links by user request

  4. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    So this is working now?
    Corrections to my coding/thoughts welcome.

  5. #5
    Join Date
    Jul 2010
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Not exactly. I've been tweaking it but it still is not 100%.

    The error messages are gone but now the Captcha is not being generated. Form validation is also failing.

  6. #6
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    You have another 404 error

    not sure what that is used for though.

    Your refresh captcha button calls I think that the 938 should be contained in a variable.

    maybe
    Last edited by Snookerman; 09-23-2010 at 05:13 PM. Reason: removed links
    Corrections to my coding/thoughts welcome.

  7. #7
    Join Date
    Jul 2010
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by bluewalrus View Post
    You have another 404 error
    not sure what that is used for though.

    Your refresh captcha button calls I think that the 938 should be contained in a variable.

    maybe
    The lift.js is a non-issue...just a clean-up issue on my part and doesn't pertain to the captcha.

    I have nooooo idea what is with the 938.

    Thanks for checking in on this, bluewalrus.
    Last edited by Snookerman; 09-23-2010 at 05:13 PM.

  8. #8
    Join Date
    Jul 2010
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    I'm happy to say this has been resolved.

Bookmarks

Posting Permissions

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