I have a problem with calling a random number.
I have created a page saying:
<img src="images.php"> <img src="images.php"> <img src="images.php"> <img src="images.php">
In theory this will show 4 random numbers as images.php says the following:
<?
header("content-type: image/gif");
session_start();
//$n is randomly selected from 1 - 10
$HTTP_SESSION_VARS['number'] = "'.$HTTP_SESSION_VARS['number'].'".$n;
echo fread(fopen("images/$n.gif","r"),filesize("images/$n.gif"));
exit;
?>
The problem is it does not show any of the images 1.gif etc.
I tried $n = rand (1, 10); but when I did that, it showed the numbers and they are all the same. Has anyone got any ideas?
Cheers
Calling Randon Numbers in an Anti Automated Signup Script
Moderator: General Moderators
what is this meant to do?
at the moment this code wont do anything because $n is not set.
this should work fine $n=rand(1,10);
but take note ( from the php manual) :
[qutoe]
In older versions of PHP, you had to seed the random number generator before use with srand(). Since 4.2.0 this is no longer necessary.
[/quote[
also, better than this is the fpassthru command i think :
becomes the more standard:
Code: Select all
//$n is randomly selected from 1 - 10
$HTTP_SESSION_VARSї'number']="'.$HTTP_SESSION_VARSї'number'].'".$n;this should work fine $n=rand(1,10);
but take note ( from the php manual) :
[qutoe]
In older versions of PHP, you had to seed the random number generator before use with srand(). Since 4.2.0 this is no longer necessary.
[/quote[
also, better than this is the fpassthru command i think :
Code: Select all
echo fread(fopen("images/$n.gif","r"),filesize("images/$n.gif"));Code: Select all
$fp = fopen($filename, 'r');
fpassthru($fp); // ** CORRECT **
fclose($fp);http://www.php.net/manual/en/function.rand.php
may this cause the problem with $n = rand(1,10);?In older versions of PHP, you had to seed the random number generator before use with srand(). Since 4.2.0 this is no longer necessary.
New version
I am now doing the following:
I am stuck as well on how to get the 4 number value to save in the sessions so that when I press submit, the numbers in the box are compared with the number values of the picture, and if they tally, they are taken to the correct page.
Help!
It works like the other code, unfortunately it shows all the numbers the same. http://www.childcarejobs.co.uk/checker is where the script is.<?
header("content-type: image/gif");
session_start();
//$n is randomly selected from 1 - 10
$n=rand(1,9);
$fp = fopen("images/$n.gif", 'r');
fpassthru($fp);
fclose($fp);
exit;
?>
I am stuck as well on how to get the 4 number value to save in the sessions so that when I press submit, the numbers in the box are compared with the number values of the picture, and if they tally, they are taken to the correct page.
Help!