Session variable

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

    Session variable

    I'm going nuts over this one. Perhaps this is kludgy, but it has worked for
    me before.

    When I give the user a form, say AAA.php that has a few fields on it, and he
    has to fill it out, I check for validity. If I find an error, I created a
    session variable like:

    $_SESSION['AnError'] = "Descriptio n of the error";

    I then call the form again with

    header("Locatio n: ThisForm.php");

    In the <body> area I have

    <?php if (isset($_SESSIO N['AnError'])) echo $_SESSION['AnError']; ?>

    Doing thing like this has worked before. Now, for a particular form when I
    try it, it doesn't display. I tested it further with

    <?php echo "Error: . $_SESSION['AnError']; ?>

    and only the "Error: " displayed. This told me that the session variable
    was not set. However, if I put echos in the code immediately after it gets
    set, then it echos and prints further that the headers have already been set
    (BTW, what does that mean?). So, I know that it is being set, it is not
    being unset anywhere, yet it isn't set when the form redisplays.

    I have been banging my head against the wall for hours now. Anyone have any
    ideas?

    Shelly


  • Shelly

    #2
    Re: Session variable


    "Shelly" <sheldonlg.news @asap-consult.com> wrote in message
    news:MMCdnVR-XpSDtk3fRVn-ow@comcast.com. ..[color=blue]
    > I'm going nuts over this one. Perhaps this is kludgy, but it has worked
    > for me before.
    >
    > When I give the user a form, say AAA.php that has a few fields on it, and
    > he has to fill it out, I check for validity. If I find an error, I
    > created a session variable like:
    >
    > $_SESSION['AnError'] = "Descriptio n of the error";
    >
    > I then call the form again with
    >
    > header("Locatio n: ThisForm.php");
    >
    > In the <body> area I have
    >
    > <?php if (isset($_SESSIO N['AnError'])) echo $_SESSION['AnError']; ?>
    >
    > Doing thing like this has worked before. Now, for a particular form when
    > I try it, it doesn't display. I tested it further with
    >
    > <?php echo "Error: . $_SESSION['AnError']; ?>
    >
    > and only the "Error: " displayed. This told me that the session variable
    > was not set. However, if I put echos in the code immediately after it
    > gets set, then it echos and prints further that the headers have already
    > been set (BTW, what does that mean?). So, I know that it is being set, it
    > is not being unset anywhere, yet it isn't set when the form redisplays.
    >
    > I have been banging my head against the wall for hours now. Anyone have
    > any ideas?
    >
    > Shelly
    >
    >[/color]

    Well, it works now. I am not sure why, but here is what I did. After I had
    echoed the variable in the <body> area, I had unset it since I didn't want
    to keep it around after the display. What I changed was that I removed
    that unset and placed it where I successfully started to upload the file
    that I wanted. In other words, where there were no client side errors.

    Could someone explain to me why that works? Is it that it does the page
    twice on redisplay, getting the variable on the first time but then it
    doesn't have it on the second pass (after the original unset)?

    Shelly


    Comment

    • Mladen Gogala

      #3
      Re: Session variable

      On Sat, 09 Jul 2005 15:52:52 -0400, Shelly wrote:
      [color=blue]
      > and only the "Error: " displayed. This told me that the session variable
      > was not set. However, if I put echos in the code immediately after it gets
      > set, then it echos and prints further that the headers have already been set
      > (BTW, what does that mean?). So, I know that it is being set, it is not
      > being unset anywhere, yet it isn't set when the form redisplays.
      >
      > I have been banging my head against the wall for hours now. Anyone have any
      > ideas?[/color]

      Yes. Probably, your web server has specified the nature of the error in
      the log file. My server (Apache 2.0.53) does it like this:


      [client 127.0.0.1] PHP Parse error: parse error, unexpected '{' in
      /home/mgogala/work/DBA/security.php on line 25, referer:


      If I am not mistaken, you haven't started the session, in the first place.
      This is how things should look:

      <?php
      require_once ('config.php');
      session_start() ;
      $DSN = $_SESSION['DSN'];
      $ADODB_FETCH_MO DE = ADODB_FETCH_NUM ;
      $ADODB_COUNTREC S = true; $db = NewADOConnectio n("oci8");
      $usr = $_GET['user'];
      $USRINFO = 'select USERNAME,
      ACCOUNT_STATUS STATUS,
      EXPIRY_DATE EXPIRES,
      DEFAULT_TABLESP ACE "DFLT. TBLSPCE",
      TEMPORARY_TABLE SPACE "TEMP. TBLSPCE",
      CREATED,PROFILE ,
      ........

      After invoking the session_start() function, I can read my connect
      information into the $DSN variable. Last, saying that "this has
      worked before" makes no sense whatsoever and is probably the single
      most irritating thing you can say to a support person. You either have
      to explain before what exact event was it working or get the support
      person to start believing in ghosts which are haunting your code. If
      the support person has geeky sense of humor, it can be rather unpleasant
      proposition.

      --


      Comment

      Working...