Post by GregWilliamBryant » Thu Jan 12, 2017 12:18 am

Capture Code not working
Version Version 1.5.5.1
Hello all,

I’m having trouble with getting the capture code working on development version of my site. My site has been running Live for some time at www.sussexcookers.com and there the old version of the capture code system which works fine there.

On my local development copy it has stopped working and I’m totally scratching my head as to why!

The problem I’m getting is a little missing image box – or on Firefox an error saying
“The image cannot be displayed, because it contains errors.”
When I navigate directly to:
opencart/index.php?route=information/contact/captcha

I’m completely satisfied that its hitting function showImage() because I’ve commented the body of the function out and replaced it with a simple echo statement which displays. If I break any syntax as well it pops a friendly error, when all the code is in place – nothing.

I’ve tried replacing captcha.php with the original, nothing happens.

Furthermore, I’ve made a temporary index.php – with just the capture code in it and some scaffolding to make it work and it works fine.

I’ve reverted to the default theme, and it still doesn’t work.

The only way I can recreate the error outside of my site is to set the index.php to incode in UTF-8-BOM which breaks it. But I can’t see any files that are encoded like that !

Any suggestions to what could be breaking it?


Posts

Joined
Wed Jun 26, 2013 6:40 pm

Post by GregWilliamBryant » Thu Jan 12, 2017 8:49 pm

I've now tried moving my code directly into the captcha() function in contact.php - and it still causes this problem.

Code: Select all

public function captcha() {
		//$this->load->library('captcha');
		
		//$captcha = new Captcha();
		
		//$this->session->data['captcha'] = $captcha->getCode();
		
		//$captcha->showImage();
		
		//this is a test
		
		$code = "code";
		
		
		$image = imagecreatetruecolor(100, 300);

        $width = imagesx($image); 
        $height = imagesy($image);
		
        $black = imagecolorallocate($image, 0, 0, 0); 
        $white = imagecolorallocate($image, 255, 255, 255); 
        
		$col1 = imagecolorallocatealpha($image, 252, 109, 10, 75); 
        $col2 = imagecolorallocatealpha($image, 252, 132, 49 , 75); 
        $col3 = imagecolorallocatealpha($image, 252, 165, 105, 75); 
		$col4 = imagecolorallocatealpha($image, 252, 209, 180, 75); 
		$col6 = imagecolorallocatealpha($image, 252, 230, 215, 0); 
         
        imagefilledrectangle($image, 0, 0, $width, $height, $col6); 
         
        imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 40, 40, $col4); 
        imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 40, 40, $col3); 
        imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 40, 40, $col2); 
		imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 40, 40, $col1); 
		imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 40, 40, $col4); 
        imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 40, 40, $col3); 
        imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 40, 40, $col2); 
		imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 40, 40, $col1); 
		
		imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 20, 20, $col4); 
        imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 20, 20, $col3); 
        imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 20, 20, $col2); 
		imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 20, 20, $col1); 
		

        //Box Around the Capture
		//imagefilledrectangle($image, 0, 0, $width, 0, $black); 
        //imagefilledrectangle($image, $width - 1, 0, $width - 1, $height - 1, $black); 
        //imagefilledrectangle($image, 0, 0, 0, $height - 1, $black); 
        //imagefilledrectangle($image, 0, $height - 1, $width, $height - 1, $black); 
         
        //imagestring($image, 10, intval(($width - (strlen($code) * 9)) / 2)+1,  intval(($height - 15) / 2)+1, $code, $black);
		
		//imagestring($image, 10, intval(($width - (strlen($code) * 9)) / 2),  intval(($height - 15) / 2), $code, $white);
	
		header('Content-type: image/jpeg');
		
		
		imagejpeg($image);
		
		imagedestroy($image);		
		
	}
The above code works fine in isolation, and I code below works fine:

Code: Select all

public function captcha() {
		//$this->load->library('captcha');
		
		//$captcha = new Captcha();
		
		//$this->session->data['captcha'] = $captcha->getCode();
		
		//$captcha->showImage();
		
		//this is a test
		echo "<h1>Test</h1>";
	}

I have a feeling that it is to do with unwanted whitespace in a file somewhere, but I can't seem to track it down!


Posts

Joined
Wed Jun 26, 2013 6:40 pm
Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 92 guests