Jump to content


This topic is now archived and is closed to further replies.


Image verification code problems

Recommended Posts

I`m having some intermittent errors with an image verification I`m using.

It sometimes displays:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]The image “http://www.domain.com/page.php” cannot be displayed, because it contains errors.[/quote]

But if I refresh the page it works fine.

In the server error log its saying:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--][06-Mar-2006 15:12:31] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/carpfish/public_html/glossary/header.inc:38) in /home/carpfish/public_html/glossary/add.php on line 13[/quote]

Yet this is what header.inc contains


echo '<!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" lang="en">
<title>Carp Fishing UK</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />

<style type="text/css">
@import url( "css/css.css" );
<br />
<table width="95%" border="0" cellspacing="0" cellpadding="0" align="center" class="logoborder">
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <td id="logostrip"><div align="center"><a href="/?index"><img src="images/logo.jpg" /></a></div></td>
          <td class="divider"> </td>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <td width="20%" valign="top">';

Below is the code I`m using.



include ('header.inc');
include ('menu.inc');

Header("Content-Type: image/png");

$im = ImageCreate(200, 40);

$txtcol = ImageColorAllocate($im, 249, 246, 73);
$bgdcol = ImageColorAllocate($im, 0, 0, 220);


$string = md5(rand(0,9999));
$new_string = substr($string, 12, 8);

ImageFill($im, 0, 0, $bgdcol);
ImageString($im, 15, 60, 10, $new_string, $txtcol);
ImagePNG($im, "verify.png");

// Snip un-needed form html out

echo "<img src="verify.png">";

// More form html stripped out


On the form processing script I have this



$random = trim($random);

if ($new_string == $random)

// Form PHP stripped out

echo "Wrong image code entered, please go back and try again.";

Can anyone see why it would intermittedly show the error?

Share this post

Link to post
Share on other sites
Remove this line, its confusing the browser. You only need that if you want the php file to be treated as an image file, where in your case you don't cause you are outputting html and saving the img data as verify.png.

[code]Header("Content-Type: image/png");[/code]

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.