denhamd2 Posted April 4, 2007 Share Posted April 4, 2007 Hi, I'm wondering could you help me... I'm sending a number of variables between 2 pages using the form GET method, and I want to store them in a session. The variables are basically called after dates and they will equal "yes" if the user has selected them. Eg. they might have selected 3 tickboxes in page 1: $07042007 = yes $18042007 = yes $22042007 = yes which get sent to page 2 via the URL is there any way of storing these in session variables of the same names? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 4, 2007 Share Posted April 4, 2007 First, you can't have variable names that start with a digit in PHP, so those are illegal. To store a value in a $_SESSION, do <?php $var = 'yes'; $_SESSION['var'] = $var; ?> Ken Quote Link to comment Share on other sites More sharing options...
denhamd2 Posted April 5, 2007 Author Share Posted April 5, 2007 I'm going to have a number of variables coming into the 2nd page, sometimes it might be 2 variables, other times it might be 17 variables, so is there any way I can store all the variables passed as session variables dynamically? Quote Link to comment Share on other sites More sharing options...
jitesh Posted April 5, 2007 Share Posted April 5, 2007 This will set all your get varibles to session with same name in get if(isset($_GET)){ foreach($_GET as $key => $value){ $_SESSION[$key] = $value; } } Quote Link to comment Share on other sites More sharing options...
denhamd2 Posted April 5, 2007 Author Share Posted April 5, 2007 great thanks is there any way I can echo all my session variable $value's then on the 2nd page (separated by <br> tags)? Quote Link to comment Share on other sites More sharing options...
jitesh Posted April 5, 2007 Share Posted April 5, 2007 if(isset($_GET)){ foreach($_GET as $key => $value){ $_SESSION[$key] = $value; } } echo "<pre>"; print_r($_SESSION); foreach($_SESSION as $key => $value){ ......................... .......................... I think you will get this } Quote Link to comment Share on other sites More sharing options...
denhamd2 Posted April 5, 2007 Author Share Posted April 5, 2007 Edit: figured it out just echoed the $value, easy! Only thing is it echos the value of the submit button from the first page, the name of this is monthsubmit, and the value is bookdays... any ideas on not having this stored as a session variable? Quote Link to comment Share on other sites More sharing options...
jitesh Posted April 5, 2007 Share Posted April 5, 2007 Explain what you need to do after storing get data into session ? Quote Link to comment Share on other sites More sharing options...
denhamd2 Posted April 5, 2007 Author Share Posted April 5, 2007 sorry mate just edited my above message, any ideas on that? Quote Link to comment Share on other sites More sharing options...
jitesh Posted April 5, 2007 Share Posted April 5, 2007 list out the varibles you do not want to set in session of previous page which are fixed and few. like this $un_nec_varible = array('monthsubmit','anyother'); if(isset($_GET)){ foreach($_GET as $key => $value){ if(!in_array($un_nec_varible,$key)){ $_SESSION["DATA"][$key] = $value; } } } echo "<pre>"; print_r($_SESSION["DATA"]); Quote Link to comment Share on other sites More sharing options...
denhamd2 Posted April 5, 2007 Author Share Posted April 5, 2007 getting the error msg for each of the variables: Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/aholiday/public_html/calendar/index2.php on line 9 Quote Link to comment Share on other sites More sharing options...
jitesh Posted April 5, 2007 Share Posted April 5, 2007 if(!in_array($key,$un_nec_varible)){ Quote Link to comment Share on other sites More sharing options...
denhamd2 Posted April 5, 2007 Author Share Posted April 5, 2007 something strange happens, it just echos the word Array any ideas? Quote Link to comment Share on other sites More sharing options...
jitesh Posted April 5, 2007 Share Posted April 5, 2007 print_r is used to print array and object. echo "<pre>"; print_r($_SESSION["DATA"]); Quote Link to comment Share on other sites More sharing options...
denhamd2 Posted April 5, 2007 Author Share Posted April 5, 2007 sorted mate thanks Quote Link to comment 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.