Jump to content

Archived

This topic is now archived and is closed to further replies.

bilis_money

incorporating session in <a href> ?

Recommended Posts

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.

[code]<?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 ...
?>
[/code]
ok, i have done this before using these codes
[code]<?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...
?>[/code]

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..

Share this post


Link to post
Share on other sites
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....
[code]<a href="yourimagescript.php?action=setcurrent&photo=$current_image">Show Image</a>[/code]

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

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.

Share this post


Link to post
Share on other sites

×

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.