Jump to content

Passing variables from a URL using the $_SESSION array


vajra_hendry

Recommended Posts

Gr8 more super noob posts :-)

 

Ok I asked something earlier and kindly got a gr8 answer that I needed to use Sessions using session_start()

 

So thats cool, went and read up on this.

 

Now I am trying to create and pass a variable to the $_SESSION array and Im doing something wrong. 

 

Here's how it goes :

 

page1.php  loads

 

<?php

 

session_start();

 

?>

 

HTML BEGINS. . . .

 

Then try to pass a variable :

 

<a href="page2.php?_SESSION ['duration']=3"><img src="images/Paypal/27.jpg"></a>

 

So I am trying to create an array in the $_SESSION called 'Duration' and make its value '3'  This value I want to be availalbe to the session

 

I have dropped the $ after the '?' as I read that when passing variables in URL's you can negate the $.

 

So when I click the image link :

 

page2.php  loads :

 

I start with :

 

<?php

 

session_start();

$duration = $_SESSION['duration'];

?>

 

HTML BEGINS . . . .

 

I then try to call the value from the 'duration' $_SESSION system variable:

 

<p>You choose to advertise for <?php echo "$duration"; ?> days</p>

 

It just returns blank.  I know this is a total joke for an experienced PHP programer, but if you could correct me that would be great

 

Thanks :-)

 

 

 

 

Thanks for the reply.

 

It seems in the below example here that the variable 'duration' is simply declared as '3' and then latter called upon.

 

What i need to do is have it such that when a user clicks on a specified image it sets a the variable 'duration' to '3'

 

Hope thats clearer, thanks.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.