vajra_hendry Posted August 10, 2007 Share Posted August 10, 2007 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 :-) Quote Link to comment https://forums.phpfreaks.com/topic/64237-passing-variables-from-a-url-using-the-_session-array/ Share on other sites More sharing options...
jitesh Posted August 10, 2007 Share Posted August 10, 2007 page1.php <?php session_start(); $_SESSION ['duration']=3 ?> <a href="page2.php"><img src="images/Paypal/27.jpg">[/url] page2.php <?php session_start(); $duration = $_SESSION['duration']; echo $duration; ?> Quote Link to comment https://forums.phpfreaks.com/topic/64237-passing-variables-from-a-url-using-the-_session-array/#findComment-320256 Share on other sites More sharing options...
vajra_hendry Posted August 10, 2007 Author Share Posted August 10, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/64237-passing-variables-from-a-url-using-the-_session-array/#findComment-320262 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.