Page 1 of 1
Assign value to variable when an image is clicked.
Posted: Thu Jun 02, 2005 8:11 am
by ChiefGoFor
Hey everyone,
I have a typical menu using roll-overimages. When they are clicked, the page changes. the code for changing pages for one of the buttons looks something like:
Code: Select all
href="index.php?page2load=pictures
What I want to do is take out the following part:
I am already using session variables throughout the site. My question is. how do I assign a value to $_SESSION['page2load'] when the button is clicked? After it is assigned, then I want to basically, redirect it back to itself, where it will load the corrisponding page. I plan to use header() to accomplish this task.
I am using PHP 4.3.10 and I would prfer not to use javascript. I will if it is the only way, I just had a goal to make this page 100% PHP.
Thank you in advance for any information you may have!
Posted: Thu Jun 02, 2005 8:22 am
by neophyte
I'm not sure I'm following you. But I think you want to get the variable like
Code: Select all
if(isset($_GET['pagetoload'])){
if ($_GET['pagetoload'] == 'blah'){
header('location:http://somewhere.com');
}
Posted: Thu Jun 02, 2005 8:30 am
by ChiefGoFor
lets assume that I have three images on my page that link to other pages. They link to:
page1.php
page2.php
page3.php
Now, when you click the first image, I want it to go to page1.php. This is a very simple thing to do. The trick is that when the user clicks the image for page1.php, I want to assign a variable, then have it go to page1.php.
Does that make more sense???
Posted: Thu Jun 02, 2005 8:40 am
by JAM
As neophyte mention:
Code: Select all
<a href="page1.php?variable=something"><img src="foo.gif" /></a>
<a href="page2.php?variable=somethingelse"><img src="foo.gif" /></a>
...then use $_GET on either pageX.php.
Posted: Thu Jun 02, 2005 12:46 pm
by ChiefGoFor
JAM, thank you for your reply!!!
I understand what you are saying. That is in fact how I have it set up now. The only issue is that I do not want the the variable to show in the address bar. This is why I wanted to set a session variable first and then redirect the page.
I hope you have some idea what can be done. I look forward to anyone's reply!
Posted: Thu Jun 02, 2005 1:03 pm
by phpScott
a slightly complicated way would be to create a form on your page(using post) that has 1 hidden field.
In your href use href="javascript:setImgName('foo.gif')"
then create a javascript function like so.
Code: Select all
function setImgName(imgName)
{
document.getElementById('disImg').value = imgName;
document.formName.submit();
}
//untested but you get the idea.
then your form will submit and you will have access to your hidden field with no variable info in the url.