Jump to content


Photo

incorporating session in <a href> ?


  • Please log in to reply
1 reply to this topic

#1 bilis_money

bilis_money
  • Members
  • PipPipPip
  • Advanced Member
  • 621 posts

Posted 11 July 2006 - 07:59 PM

ok, this are just the partial codes...

i'm currently building a photo gallery and it works fine.
now these codes is part of displaying the partial images
and when you click a photo the
$_SESSION['cur_photo'] = $photo_name; must assign properly and point
to the current clicked photo. a such it can be use on the second page.

<?php
    ... more codes here ...

	echo $photo_name;
	echo ('<td><center><a href="img_info.php">
	<img src="'.$cur_img.'" />
	$_SESSION['cur_photo'] = $photo_name; //this should be assigned to
                                                                // point on a current photo,
                                                                // but it's not.
	</a></center></td>');

    ... more codes here ...
?>
ok, i have done this before using these codes
<?php
        ... more codes here...

        echo ('<td><center><a href="img_info2.php?cur_img='.$cur_img.'">
	<img src="'.$cur_img.'" />
	</a></center></td>');
	$i++;

        ... more codes here...
?>

but what i want is to use session, the only problem was it doesn't point
on the current clicked photo, so my question is how to incorporate a
session assignment in the <a href> so that it will point on the right
photo name?


thank you very much in advance, your answer will be appreciated much.

and by the way what is this subject called "The assignment to <a href>"?
Is this a specific topic on HTML or on PHP?
please let me know cause i want to read more on this topic about assignment
on <a href>.

thanks again..



#2 robos99

robos99
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 11 July 2006 - 08:24 PM

I'm not 100% sure what you're trying to acheive, but it appears to me you want to assign the name of the photo to a session variable upon clicking the link. It appears your problem is you're trying to assign this session variable at the same time as displaying the link....which won't work since the current photo would not be set, or not be accurate. Try adding a query string to your link like so....
<a href="yourimagescript.php?action=setcurrent&photo=$current_image">Show Image</a>

Then add a section like this to your photo script:
if($_GET['action']=='setcurrent'){
    $_SESSION['current_photo']=$_GET['photo'];
   }

Keep in mind this is overly simplified. You'll want to properly "clean" the input from the query string depending on what you're doing with it, so someone can't just change the value and crash your system. And you'll need to do a urlencode on the image name if it's an actual file name and not just a number referenced to a database or something.

I'm not entirely sure what you're trying to accomplish without seeing all of your code. Is having $i++ a part of your method of setting the session variable or is that part of the rest of the code? You have variables that don't appear to be established either...so I'm assuming you set them earlier in the code you didn't show us.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users