Session variable

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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'] = "Description of the error";

I then call the form again with

header("Location: ThisForm.php");

In the <body> area I have

<?php  if (isset($_SESSION['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  


Re: Session variable

Quoted text here. Click to load it

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)?


Re: Session variable

On Sat, 09 Jul 2005 15:52:52 -0400, Shelly wrote:

Quoted text here. Click to load it

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] 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:

    require_once ('config.php');
    $DSN = $_SESSION['DSN'];
    $ADODB_COUNTRECS = true;     $db = NewADOConnection("oci8");
    $usr = $_GET['user'];
    $USRINFO = 'select USERNAME,
                 ACCOUNT_STATUS STATUS,
                 EXPIRY_DATE EXPIRES,

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


Site Timeline