Solved

Change a Session Variable onClick?

Posted on 2010-09-10
4
868 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
  • 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 109

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

831 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