?
Solved

Change a Session Variable onClick?

Posted on 2010-09-10
4
Medium Priority
?
881 Views
Last Modified: 2012-05-10
Hi,

I basically have two images - and by clicking on image A it will hyperlink to the next page, while changing $_SESSION['kit'] to 0.  Clicking image B will also hyperlink to the next page but then change $_SESSION['kit'] to 1.  Is there a way to do this without JavaScript?  I don't want to have the $_SESSION updated on the hyperlinked page, I would like it all on the same page as the images.

Thank you!
0
Comment
Question by:maeve100
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Author Comment

by:maeve100
ID: 33651389
If this is only possible with JavaScript - is there a way to simply post a hidden variable, and then have the next page update the the session variable?  I know I can create a link "page.php?kit=1" and that would do the trick, but I want to hide that "kit=1 variable from the user.

How do I set up a hidden variable that changes based on which image they click?
0
 
LVL 9

Accepted Solution

by:
khaledf earned 1000 total points
ID: 33651736
did you try to make the images part of a form that has POST method?
i think that would solve your issue.
0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1000 total points
ID: 33657696
The usual design pattern would put the value you want to transmit into the URL for the next page, and let the next page script read the value out of $_GET['kit'] into the $_SESSION['kit'] value.

Calling page would be something like this:
<a href="next.php?kit=0"><img src="image_a.png" /></a>
<a href="next.php?kit=1"><img src="image_b.png" /></a>

Receiving page would be something like this:
if ( ($_GET['kit'] == '0') || ($_GET['kit'] == '1') ) $_SESSION['kit'] = $_GET['kit'];

The alternative might be an AJAX solution -- but that involves JavaScript as well as a lot more than three lines of code!

HTH, ~Ray
0
 

Author Closing Comment

by:maeve100
ID: 33779605
don't think what I wanted to do was totally possible, but this was close.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question