Solved

Change a Session Variable onClick?

Posted on 2010-09-10
4
866 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 108

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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 look for a specific file type in a local or remote server directory using PHP.

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now