www.webdeveloper.com
Results 1 to 5 of 5

Thread: SESSION variables disappearing.

  1. #1
    Join Date
    Aug 2010
    Posts
    81

    Question SESSION variables disappearing.

    Hi all.
    I've a form that posts to another page. That page turns all the POST variables into SESSION variables (as well as cleans them for MySQL insertion):

    PHP Code:
        foreach ($_POST as $k=>$v) {
            
    $v field_sanitize_basic($v);
            
    $_SESSION['form_data'][$k] = $v;
            
    $_SESSION[$k] = $v;
            
    $_POST[$k] = $v;
        } 
    When I print all the session variables on that receiving page, there they are:
    PHP Code:
    foreach($_SESSION as $key=>$value)
    {
    print 
    $key." = ".$value."<br>";
    unset(
    $value);

    HTML Code:
    form_data = Array
    submit = Submit Changes >>
    logged_in = 1
    user_role = 102
    user_id = 1
    user_username = lwatts
    last_hit = 2011-06-20 13:36:12
    txt_sudiv_geninfo = <p>This is a test of textfield 1.</p>
    txt_sudiv_notes = <p>This is a test of textfield 2.</p>
    txt_sudiv_events =
    txt_sudiv_news =
    txt_sudiv_recog =
    txt_sudiv_roster =
    But when I go BACK to the previous, form page, when I list the SESSIONS (same print script as above), the SESSION variables for the form don't show up:
    HTML Code:
    form_data = Array
    submit = Select SU
    logged_in = 1
    user_role = 102
    user_id = 1
    user_username = lwatts
    last_hit = 2011-06-20 13:36:12
    sel_suinfo = 703
    Why in the world would this be? The SESSION is staying active, obviously by the persistence of the other variables like "user_role," but just the SESSIONs that are part of the POST just go away.

    Any ideas for what I need to look into, I would greatly appreciate it!
    Thanks,
    Liam

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,176
    Quote Originally Posted by mechphisto View Post
    ...
    But when I go BACK to the previous, form page, when I list the SESSIONS (same print script as above), the SESSION variables for the form don't show up:
    ...
    When you say that your "go BACK", are you talking about using the browser's "Back" button? If so, then it's probably not sending a new HTTP request, but just displaying the page from its local cache. If so, for a sanity check, after going back, doing a page refresh should show all the session data in question -- assuming nothing else is wrong.

    If that is the case, I'm not sure there is any work-around at the browser level, but you could build a "Back" button into the page that links to the first page, with a warning to the user not to use the browser's "Back" button, if it is an important functional requirement to be able to go back yet have those session values present.

    Or, I may be totally misunderstanding the problem.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jun 2011
    Posts
    6
    Are you calling session_start() at the top of both pages?

    Do both pages have the "www" before the domain? I had a site recently that if you logged in at domain.com, then click a link at www.domain.com, it would ask you to login again, thinking it was a different user / server or whatever.

  4. #4
    Join Date
    Aug 2010
    Posts
    81
    Quote Originally Posted by NogDog View Post
    When you say that your "go BACK", are you talking about using the browser's "Back" button? [...]

    Or, I may be totally misunderstanding the problem.
    No, I think you understand the problem. Unfortunately, when I click the back button AND when I'm there and refresh the page, the browser asks me to "resend" the form info. I have no choice, and when I do, still those SESSION keys just aren't there. *sigh*
    Maybe a lost cause.
    Thanks for the replies!!

  5. #5
    Join Date
    Aug 2010
    Posts
    81
    Quote Originally Posted by Magic_Knight View Post
    Are you calling session_start() at the top of both pages?

    Do both pages have the "www" before the domain? I had a site recently that if you logged in at domain.com, then click a link at www.domain.com, it would ask you to login again, thinking it was a different user / server or whatever.
    Yeah, session_start() is the first thing on all pages.
    As for the form's "action," I'm using relative paths. It's going to "suadmin-proc.php" as opposed to "http://www.domainname.com/pages/suinfo-proc.php".
    Think that'll make a difference?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles