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)

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

<?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 ......
?>

Link to comment
Share on other sites

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.

Link to comment
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.