943,733 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 622
  • PHP RSS
Sep 25th, 2009
0

SESSION variable problem

Expand Post »
This is content of in.header.php
PHP Syntax (Toggle Plain Text)
  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
PHP Syntax (Toggle Plain Text)
  1. require_once 'inc.header.php'
  2. $_SESSION["Inputs"]["name"]="MyName";
  3. $_SESSION["Inputs"]["surname"]="MySurname";

This is step1.php
PHP Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 38
Solved Threads: 0
Master Poster
veledrom is offline Offline
724 posts
since Apr 2008
Sep 25th, 2009
0

Re: SESSION variable problem

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.
Reputation Points: 101
Solved Threads: 74
Posting Pro in Training
blocblue is offline Offline
427 posts
since Jan 2008
Sep 25th, 2009
-1

Re: SESSION variable problem

PHP Syntax (Toggle Plain Text)
  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.
Sponsor
Featured Poster
Reputation Points: 1048
Solved Threads: 946
Sarcastic Poster
ardav is offline Offline
6,678 posts
since Oct 2006
Sep 26th, 2009
0

Re: SESSION variable problem

Solved.
inc.header.php
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. session_start();
  3. ?>

index.php
PHP Syntax (Toggle Plain Text)
  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
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. require_once 'inc.header.php';
  3. $_SESSION["Inputs"]["age"]=$_POST["age"];;
  4.  
  5. echo "<pre>";
  6. print_r($_SESSION["Inputs"]);
  7. ?>
Reputation Points: 38
Solved Threads: 0
Master Poster
veledrom is offline Offline
724 posts
since Apr 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Crystal report with PHP
Next Thread in PHP Forum Timeline: Request for Max Upload Filesize Change





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC