Re: My own "captcha" from 2 years ago......

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jake McHenry wrote:
> Like I said... Even if they have sound turned on.. Which all my sets do...
> Most of them don't have speakers... That was put into effect over a year ago
> due to some people listening to those damn screaming prank things at full
> volume...

and didn'tr we all have a fun with those :-/

> Anyways... 

indeed ...

> I was searching the php site, and it said there used to
> be a bug that looks somewhat similar to my problem, but it said it was fixed
> long ago... Not sure if this is even close to it or not, but this is the
> first time I've run into a sessions problem.....

you don't have a session problem and your not looking at a bug either.
you have a PEBKAC/logic problem with regard to storage/retrieval of the
security code.

> 
> Just to simplify...
> 
> I have this on index.php
> 
> <?php
> session_start();
> 
> $before = $_SESSION['code'];
> 
> echo '<img src=image.php>';
> 
> $after = $_SESSION['code'];
> 
> echo $before .' ' . $after;
> ?>

$before and $after are always going to be the same because image.php
is not being run in the line "echo '<img src=image.php>';"

imagine 3 files and note that in this psuedo solution the
image is *not* generated in the file that outputs it but rather in the file
that outputs and processes the form:

	seccode.inc.php <-- some security code functions
	secform.php  	<-- output the form and processes it's own 'POST'
	secimage.php 	<-- outputs the relevant/current 'security image' for secform.php

the psuedo contents of these 2 files should be something *like* this:

seccode.inc.php
-------------- 8< ------------------
<?php

function genSecCodeInfo()
{
	// generate a random wotsit
	$code = rand();

	$imgloc = "/path/to/sec/images/{$code}.jpg";
	/* create an image! */	
	/* save the image to $imgloc */

	$_SESSION['seccodeinfo'] = array(
		'code'  => $code,
		'imgloc'=> $imgloc,
	);
}

function getCurSecCodeInfo()
{
	if (isset($_SESSION['seccodeinfo']))
		return $_SESSION['seccodeinfo'];

	return null;
}


secform.php
-------------- 8< ------------------
<?php

session_start();


if (!empty($_POST) && ($info = getCurSecCodeInfo())) {
	if ($_POST['seccode'] == $info['code']) {
		echo 'good dog!';
		exit;
	} else {
		echo 'try again mutt.';
	}
}

// create/refresh the security code info & image
genSecCodeInfo();

echo '
	<form action="" method="post">
	<image src="/secimage.php" alt="you are blind and we didn't bother to make this accessible" />
	<input type="text" name="seccode" />
	<input type="submit" name="submit" value="GO" />
	</form>
';


secimage.php
-------------- 8< ------------------
<?php

session_start();

if ($info = getCurSecCodeInfo()) {
	/* output all the required headers, etc */
	readfile($info['imgloc']);
} else {
	// there is no spoon (I mean image)
	// so an error image or something
}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux