SESSION variable problem

Thread Solved

Join Date: Apr 2008
Posts: 495
Reputation: veledrom is an unknown quantity at this point 
Solved Threads: 0
veledrom veledrom is offline Offline
Posting Pro in Training

SESSION variable problem

 
0
  #1
Sep 25th, 2009
This is content of in.header.php
  1. if(!isset($session_id) || empty($session_id)) {
  2. session_start();
  3. $_SESSION["Inputs"]=array();
  4. }

This is index.php which also has form objects that POSTs other values to step1.php
  1. require_once 'inc.header.php'
  2. $_SESSION["Inputs"]["name"]="MyName";
  3. $_SESSION["Inputs"]["surname"]="MySurname";

This is step1.php
  1. require_once 'inc.header.php'
  2. $_SESSION["Inputs"]["age"]=$_POST["textboxAge"];
  3. print_r($_SESSION["Inputs"]);

Problem is print_r prints only Array (). I cannot see name, surname and age.

What do i miss?

Thanks in advance
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 141
Reputation: robothy is an unknown quantity at this point 
Solved Threads: 19
robothy robothy is offline Offline
Junior Poster

Re: SESSION variable problem

 
0
  #2
Sep 25th, 2009
Hi,

If you haven't already read the function description for session_start(), read it here.

You have to call session_start at the beginning of every new page to continue the previous session. You may also find it beneficial to use session_name.

Check out the examples on the link I included.

R.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 955
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 126
ardav's Avatar
ardav ardav is offline Offline
Posting Shark

Re: SESSION variable problem

 
0
  #3
Sep 25th, 2009
  1. if(!isset($session_id) || empty($session_id)) {
  2. session_start();
  3. $_SESSION["Inputs"]=array();
  4. }

It's not clear where $session_id is declared if at all, therefore the code will always run regardless of whether you have a $_SESSION variable. In addition, $_SESSION["Inputs"]=array(); may overwrite previous $_SESSION variables, leaving you with an empty array.
"...the woods would be a very silent place if no birds sang except for the best"
All opinions count.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 495
Reputation: veledrom is an unknown quantity at this point 
Solved Threads: 0
veledrom veledrom is offline Offline
Posting Pro in Training

Re: SESSION variable problem

 
0
  #4
Sep 26th, 2009
Solved.
inc.header.php
  1. <?php
  2. session_start();
  3. ?>

index.php
  1. <?php
  2. require_once 'inc.header.php';
  3. $_SESSION["Inputs"]["name"]="MyName";
  4. $_SESSION["Inputs"]["surname"]="MySurname";
  5.  
  6. echo "<pre>";
  7. print_r($_SESSION["Inputs"]);
  8. ?>
  9.  
  10. <form action="next.php" method="post">
  11. <input type="textbox" name="age" value="15" />
  12. <input type="submit" name="submit" value="send" />
  13. </form>

next.php
  1. <?php
  2. require_once 'inc.header.php';
  3. $_SESSION["Inputs"]["age"]=$_POST["age"];;
  4.  
  5. echo "<pre>";
  6. print_r($_SESSION["Inputs"]);
  7. ?>
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC