num parameters passed via session

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
okioki13
Forum Newbie
Posts: 2
Joined: Sun Feb 21, 2010 12:59 pm

num parameters passed via session

Post by okioki13 »

Hi,
I passed rnd int parameter via session and later wanted to generate picture (circles) - amount based on that session parameter. Did not worked. PLS help. Thanks.

Session:
session_register("sc");
session_register("se");
if (empty($_SESSION["sc"])) {
$_SESSION['sc']= rand(1,5);
$_SESSION['se']= rand(1,5);
}

PICTURE:

$size = 300;
$image=imagecreatetruecolor($xscale,$yscale);
$back = imagecolorallocate($image, 255, 255, 255);
$border = imagecolorallocate($image, 0, 0, 0);
imagefilledrectangle($image, 0, 0, $xscale - 1, $yscale - 1, $back);
imagerectangle($image, 0, 0, $xscale - 1, $yscale - 1, $border);
$xc=$_SESSION['sc'];
for ( $counter = 1; $counter<=$xc; $counter += 1) {
$xp=rand($mincirc, $xscale-$mincirc);
$yp=rand($mincirc, $yscale-$mincirc);
$xs=rand($mincirc, $maxcirc);
$v11=rand(0, 255);
$v12=rand(0, 255);
$v13=rand(0, 255);
$yel = imagecolorallocatealpha($image, $v11, $v12, $v13, 75);
imagefilledellipse($image, $xp, $yp, $xs, $xs, $yel);
}
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
return $image;
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: num parameters passed via session

Post by requinix »

General Posting Guidelines

1. Post code in tags.
2. Give detailed explanations of what you're trying to do and what problems you're having.
3. We don't fix your problems - we tell you what you can try.

You remember to session_start() on both pages?
okioki13
Forum Newbie
Posts: 2
Joined: Sun Feb 21, 2010 12:59 pm

Re: num parameters passed via session

Post by okioki13 »

OK,
So, session is started each time on index.php, as first step.
Than later on there is a picture generated by php file, the source of the picture generator is shown in PICTURE section.

If I include similar script like :

for(...){
echo $counter.
}

I can see numbers generated by script. That part is ok.
But:
1. if I use same steps to generate circles, it does not work
2. if I replace session parameter with exact number (3 or 4), it works.

So I can see, that the problem is somewhere between passing the value from session into loop.
But I am not able to solve this.
Post Reply