My SESSION array does not PERSIST???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michelle

    My SESSION array does not PERSIST???

    Hi all,

    I am trying to store data in a $_SESSION variable (an array), but it reverts to
    empty every time my page is refreshed (due to a submit button click).

    I read the answer to the post "$_SESSION comes empty on next page" dated
    2/4, whaich seems to be my problem. But the suggestions do not help me at all
    <see 1 & 2 below>

    1-have you set session.save_pa th ?
    2-if you are using virtualhosts put this at the top of your .php file:
    session_set_coo kie_params(3200 , '/', $_SERVER['HTTP_HOST']);


    I have tested the array $_SESSION['list_array'] with both empty and !isset
    and it returns true in both cases after a page refresh or when moving to
    another page all together.

    Is there something that I am missing...here is some of my code:

    <?php

    if (!isset($_POST['build_it'])) // if this is not the final submit, but
    the first form display or redisplay
    {
    if (isset($_POST['add'])) // this is just the posting to the array
    {
    if (empty($_SESSIO N['list_array']))
    {
    $_SESSION['list_array'] = array(1 => $_POST['list_member']);
    print "created and added...<br />";
    }
    else
    {
    $_SESSION['list_array'][] = $_POST['list_member'];
    print "added...<b r />";
    }
    print_r ($_SESSION['list_array']);
    }

    TIA,
    Miki
  • Chung Leong

    #2
    Re: My SESSION array does not PERSIST???

    Is session.auto_st art set to 1 in php.ini? If not, then settings $_SESSION
    will have no effect and the array will remain empty. Call session_start() at
    the beginning of your script.

    Uzytkownik "Michelle" <miki@spam_me.n et> napisal w wiadomosci
    news:pMWVb.2141 47$nt4.995530@a ttbi_s51...[color=blue]
    > Hi all,
    >
    > I am trying to store data in a $_SESSION variable (an array), but it[/color]
    reverts to[color=blue]
    > empty every time my page is refreshed (due to a submit button click).
    >
    > I read the answer to the post "$_SESSION comes empty on next page" dated
    > 2/4, whaich seems to be my problem. But the suggestions do not help me at[/color]
    all[color=blue]
    > <see 1 & 2 below>
    >
    > 1-have you set session.save_pa th ?
    > 2-if you are using virtualhosts put this at the top of your .php file:
    > session_set_coo kie_params(3200 , '/', $_SERVER['HTTP_HOST']);
    >
    >
    > I have tested the array $_SESSION['list_array'] with both empty and !isset
    > and it returns true in both cases after a page refresh or when moving to
    > another page all together.
    >
    > Is there something that I am missing...here is some of my code:
    >
    > <?php
    >
    > if (!isset($_POST['build_it'])) // if this is not the final submit, but
    > the first form display or redisplay
    > {
    > if (isset($_POST['add'])) // this is just the posting to the array
    > {
    > if (empty($_SESSIO N['list_array']))
    > {
    > $_SESSION['list_array'] = array(1 => $_POST['list_member']);
    > print "created and added...<br />";
    > }
    > else
    > {
    > $_SESSION['list_array'][] = $_POST['list_member'];
    > print "added...<b r />";
    > }
    > print_r ($_SESSION['list_array']);
    > }
    >
    > TIA,
    > Miki[/color]


    Comment

    • Michelle

      #3
      Re: My SESSION array does not PERSIST???

      Chung Leong wrote:[color=blue]
      > Is session.auto_st art set to 1 in php.ini? If not, then settings $_SESSION
      > will have no effect and the array will remain empty. Call session_start() at
      > the beginning of your script.
      >
      > Uzytkownik "Michelle" <miki@spam_me.n et> napisal w wiadomosci
      > news:pMWVb.2141 47$nt4.995530@a ttbi_s51...
      >[color=green]
      >>Hi all,
      >>
      >>I am trying to store data in a $_SESSION variable (an array), but it[/color]
      >
      > reverts to
      >[color=green]
      >>empty every time my page is refreshed (due to a submit button click).
      >>
      >>I read the answer to the post "$_SESSION comes empty on next page" dated
      >>2/4, whaich seems to be my problem. But the suggestions do not help me at[/color]
      >
      > all
      >[color=green]
      >><see 1 & 2 below>
      >>
      >>1-have you set session.save_pa th ?
      >>2-if you are using virtualhosts put this at the top of your .php file:
      >>session_set_c ookie_params(32 00, '/', $_SERVER['HTTP_HOST']);
      >>
      >>
      >>I have tested the array $_SESSION['list_array'] with both empty and !isset
      >>and it returns true in both cases after a page refresh or when moving to
      >>another page all together.
      >>
      >>Is there something that I am missing...here is some of my code:
      >>
      >><?php
      >>
      >>if (!isset($_POST['build_it'])) // if this is not the final submit, but
      >>the first form display or redisplay
      >>{
      >>if (isset($_POST['add'])) // this is just the posting to the array
      >>{
      >>if (empty($_SESSIO N['list_array']))
      >>{
      >>$_SESSION['list_array'] = array(1 => $_POST['list_member']);
      >>print "created and added...<br />";
      >>}
      >>else
      >>{
      >>$_SESSION['list_array'][] = $_POST['list_member'];
      >>print "added...<b r />";
      >>}
      >>print_r ($_SESSION['list_array']);
      >>}
      >>
      >>TIA,
      >>Miki[/color]
      >
      >
      >[/color]
      Thanks...I just found out that session_start() is mandatory on every page that uses session vars.
      Too bad the PHP.net docs don't say this, nor does my text "PHP and MySQL Web Development" by Welling
      and Thomson...in fact the text says that it is just a good idea to use session_start() on a page
      that accesses session vars...hmmm!

      Thanks, again this group is great!

      Comment

      • Recoura Tim

        #4
        Re: My SESSION array does not PERSIST???

        [color=blue]
        > Thanks...I just found out that session_start() is mandatory on every page[/color]
        that uses session vars.[color=blue]
        > Too bad the PHP.net docs don't say this, nor does my text "PHP and MySQL[/color]
        Web Development" by Welling[color=blue]
        > and Thomson...in fact the text says that it is just a good idea to use[/color]
        session_start() on a page[color=blue]
        > that accesses session vars...hmmm!
        >[/color]
        your text does say it, I have it too.


        Comment

        Working...