Jump to content

Storing variables in a session


denhamd2

Recommended Posts

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?

Link to comment
Share on other sites

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
}

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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"]);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.