Assign value to variable when an image is clicked.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ChiefGoFor
Forum Newbie
Posts: 4
Joined: Thu Jun 02, 2005 7:46 am
Location: Missouri, USA
Contact:

Assign value to variable when an image is clicked.

Post 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:

Code: Select all

?page2load=pictures
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!
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post 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');
}
ChiefGoFor
Forum Newbie
Posts: 4
Joined: Thu Jun 02, 2005 7:46 am
Location: Missouri, USA
Contact:

Post 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???
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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.
ChiefGoFor
Forum Newbie
Posts: 4
Joined: Thu Jun 02, 2005 7:46 am
Location: Missouri, USA
Contact:

Post 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!
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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.
Post Reply