Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Change a Session Variable onClick?

Posted on 2010-09-10
4
Medium Priority
?
884 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …
Suggested Courses

610 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