Jump to content


Photo

Image verification code problems


  • Please log in to reply
1 reply to this topic

#1 sford999

sford999
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 07 March 2006 - 01:09 AM

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

<?php

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">
<head>
<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" );
</style>
</head>
<body>
<br />
<table width="95%" border="0" cellspacing="0" cellpadding="0" align="center" class="logoborder">
  <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td id="logostrip"><div align="center"><a href="/?index"><img src="images/logo.jpg" /></a></div></td>
        </tr>
        <tr>
          <td class="divider"> </td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="20%" valign="top">';
          
?>


Below is the code I`m using.

<?php

session_start();
$new_string;
session_register('new_string');

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);

srand((double)microtime()*1000000);

$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");
ImageDestroy($im);

// Snip un-needed form html out

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

// More form html stripped out

?>

On the form processing script I have this

<?php

session_start();

$random = trim($random);

if ($new_string == $random)
{

//--------------------------
// Form PHP stripped out
//--------------------------

}
else
{
echo "Wrong image code entered, please go back and try again.";
}
?>

Can anyone see why it would intermittedly show the error?


#2 jordie

jordie
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 07 March 2006 - 02:45 AM

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.

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users