Jump to content

Recommended Posts

Im making my first captcha script and what I found on the net works great but Im not able to output any html after the image is created. Here is what I have so far:

<?php
$md5 = md5(microtime() * mktime());
$string = substr($md5,0,5);
$key = md5($string);
setcookie("BrandonE97_Captcha", $key, 0);
$captcha = imagecreatefrompng("./captcha.png"); 
$text = imagecolorallocate($captcha, 0, 153, 255);
$line = imagecolorallocate($captcha,255,255,255);
$x1 = rand(0,80);
$y1 = rand(0,10);
$x2 = rand(0,80);
$y2 = rand(40,30);
imageline($captcha,$x1,$y1,$x2,$y2,$line);
$x1 = rand(0,80);
$y1 = rand(0,10);
$x2 = rand(0,80);
$y2 = rand(40,30);
imageline($captcha,$x1,$y1,$x2,$y2,$line);
$x1 = rand(0,80);
$y1 = rand(0,10);
$x2 = rand(0,80);
$y2 = rand(40,30);
imageline($captcha,$x1,$y1,$x2,$y2,$line);
imagestring($captcha, 5, 20, 10, $string, $text);
header("Content-type: image/png");
imagepng($captcha);
header("Content-Type: text/html"); // I added this thinking it may fix my problem but I still have no output.
?>
<br />
<?php
if ($_COOKIE['BrandonE97_Captcha'] == $key) { // all of this is for testing
echo('hi');
}
else {
echo('no');
}
?>

Link to comment
https://forums.phpfreaks.com/topic/50581-changing-headers/
Share on other sites

You are contradicting yourself. Most captcha scripts have a single file that generates the image because of the fact you can only output one header.

 

You may be able to use output buffering to solve this, but as far as this is concerned you just need to reference this script via the image html code.

 

<img src="yourCaptchaScript.php" />

 

 

Link to comment
https://forums.phpfreaks.com/topic/50581-changing-headers/#findComment-249056
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.