Jump to content

[SOLVED] Passing a variable to an image-generating script


alhena

Recommended Posts

I have a script that generates an image, and I need to pass a variable to it. The catch? I don't want to put the variable into the URL, because it can be too easily manipulated. The relevant code looks something like this:

 

for ($i = 1; $i <= $j; $i++){

 

echo '<img src="image.php"> ';

 

}

 

And I want the image.php script to know what value $i has. I have tried using a temporary session variable, but the image script only recognizes the one that was last set. For example, if the for-loop runs five times, I'd get five images, all of them with 5 as the variable, which is wrong because it should (obviously) go from 1-5.

 

Any ideas how to solve this?

first idea that comes to my mind is to have:

 

$fh = fopen('loopIteration.txt', 'w');

$fwrite($fh, $i);

$fclose($fh);

 

inside the for loop (before you echo the img tag), and then read the contents of loopIteration.txt in image.php.

 

very likely there is a better way of doing this, but you can use this until something better is suggested.

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.