Jump to content

Include gd-created image AND variables used to create it...


TutorMe

Recommended Posts

I am trying to make my own captcha.  I have the image creation part done, but I can't get the image into an php/html page.  I have tried include('file'), but it throw image/png headers, and confuses the script (does that make sense?).

 

Is there a way I can include the file that creates the image (image.php) as an image, along with the variables used to create it?  ($string for example)

Thanks.  That's weird though.  Image tags were the first thing I tried, and they didn't work.  I must have typed something wrong.

 

I haven't really worked with sessions.  I'll look up information on them, but do you think you could give an example of what i should use to set the variables, and to retrieve the variables?

<?php
//on the page with the form
//start session at top of script before any output even whitespace
session_start();

$_SESSION['captcha_text'] = $captcha_text;
$_SESSION['strlength'] = $strlength;
?>
<form ....
</form>
<img scr="image.php" />

 

image.php code

<?php
session_start();
$strlength = $_SESSION['strlength'];
$captcha_text= $_SESSION['captcha_text'];
//snip ......
?>

you can set the session in the image creator that isn't a problem, just as long as you don't expect to validate on that page as a refresh/ajax of some sort will be needed to recovery said value.  This is a common practice

 

Parent page

<?php session_start();?>
<img src="image.php" />

 

image.php

<?php
$_SESSION['secret'] = rand_str();
// ...
?>

 

that is legit to do, but that session's value will be a mystery until the user refreshes a page on your server and you can recover the session value.

Archived

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

×
×
  • 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.