MmmVomit Posted September 20, 2007 Share Posted September 20, 2007 I'm working on the registration page of my website, and am building in a system where the user has to read something out of a dynamically created image. I can create the image just fine, but how do I get it to display in a web page? Here's what I've figured out to do on my own. <?php // mainpage.php session_start() $_SESSION['capcha_string'] = 'capcha'; ?> <html><head><title> Main Page </title></head> <body> <p>Capcha</p> <img src="image.php"> </body></html> <?php // image.php session_start(); header("Content-type: image/gif"); $img = imagecreate(); /* snip. print $_SESSION['capcha_string'] in $img do more image manipulation */ imagegif($img); imagedestroy($img); ?> Now, this works, but it seems very kludgy. Is there a better way to do this that I'm simply missing? I checked the faq/code repository and didn't find anything. Quote Link to comment https://forums.phpfreaks.com/topic/70024-solved-displaying-dynamicly-created-images/ Share on other sites More sharing options...
Lumio Posted September 20, 2007 Share Posted September 20, 2007 You missed the Content-type thing... <?php //... your code header('Content-type: image/gif'); imagegif($img); //rest ?> Quote Link to comment https://forums.phpfreaks.com/topic/70024-solved-displaying-dynamicly-created-images/#findComment-351676 Share on other sites More sharing options...
Orio Posted September 20, 2007 Share Posted September 20, 2007 In the top of the image-php file use header() to tell the browser its a pic: header('Content-type: image/gif'); Orio. Quote Link to comment https://forums.phpfreaks.com/topic/70024-solved-displaying-dynamicly-created-images/#findComment-351677 Share on other sites More sharing options...
MmmVomit Posted September 20, 2007 Author Share Posted September 20, 2007 Okay, edited. That wasn't my question, though. I called the header correctly in the live code, I just forgot to include it in my post. My question is if there's a better way to do it than having separate php files and passing data via the $_SESSION array. Quote Link to comment https://forums.phpfreaks.com/topic/70024-solved-displaying-dynamicly-created-images/#findComment-351685 Share on other sites More sharing options...
MmmVomit Posted September 20, 2007 Author Share Posted September 20, 2007 bump. If this is a common implementation, please say so. Quote Link to comment https://forums.phpfreaks.com/topic/70024-solved-displaying-dynamicly-created-images/#findComment-351811 Share on other sites More sharing options...
MmmVomit Posted September 21, 2007 Author Share Posted September 21, 2007 Okay, I think I solved it. <?php // image.php session_start(); header("Content-type: image/gif"); $img = imagecreate(); $rand_string = md5(rand()); $_SESSION['capcha'] = $rand_string; /* snip. print $rand_string in image do more image manipulation */ imagegif($img); imagedestroy($img); ?> The string in the image is stored in the session data, and this can be checked against what was entered in the form. Quote Link to comment https://forums.phpfreaks.com/topic/70024-solved-displaying-dynamicly-created-images/#findComment-352516 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.