Solved

Change a Session Variable onClick?

Posted on 2010-09-10
4
874 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 250 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 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

691 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