Can't read $_SESSION variables set by previous request, AJAX

My page loads, and calls an init() function that returns content to a
div on the page, as well as setting a $_SESSION variable. The content
it returns includes a link that calls the same variable, but I get an
error that says the index isn't defined.

The second two calls are AJAX-generated. The second call immediately
echos the $_SESSION variable back after it sets it, and it sets it
properly. But the subsequent request doesn't see it.

I can't figure this one out, and this sort of function is vital to the
site I'm building.

Things I've already done:

Put session_start() in the functions that get called after the initial
pageload. Just generates warnings that a session has already been
started (by the original pageload).

Checked to make sure the same session is being used by all requests,
and it is (according to session_id).

Any help is appreciated.
zburnham [ So, 18 Februar 2007 01:52 ] [ ID #1632934 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

Evil Otto wrote:
> My page loads, and calls an init() function that returns content to a
> div on the page, as well as setting a $_SESSION variable. The content
> it returns includes a link that calls the same variable, but I get an
> error that says the index isn't defined.
>
> The second two calls are AJAX-generated. The second call immediately
> echos the $_SESSION variable back after it sets it, and it sets it
> properly. But the subsequent request doesn't see it.
>
> I can't figure this one out, and this sort of function is vital to the
> site I'm building.
>
> Things I've already done:
>
> Put session_start() in the functions that get called after the initial
> pageload. Just generates warnings that a session has already been
> started (by the original pageload).
>
> Checked to make sure the same session is being used by all requests,
> and it is (according to session_id).
>
> Any help is appreciated.
>

session_start() must be called before ANY OUTPUT - including whitespace,
DOCTYPE statement, <head>, etc. 99% of the time people ask about
session problems here, they have already sent output before the call to
session_start() is made, but don't have error reporting enabled.

As the very first lines in the page you're loading, try the following:

<?php
error_reporting(E_ALL);
ini_set("display_errors","1");
?>

No whitespace or anything else before it.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex [at] attglobal.net
==================
Jerry Stuckle [ So, 18 Februar 2007 04:23 ] [ ID #1632935 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

Evil Otto wrote:

> Put session_start() in the functions that get called after the initial
> pageload. Just generates warnings that a session has already been
> started (by the original pageload).

You are supposed to use one session_start() per script, say your AJAX will
call the getnewcars.php to get a result, then you have session_start() first
in that script, and thats all, nothing in the functions that are called from
that script.

--

//Aho
Shion [ So, 18 Februar 2007 09:38 ] [ ID #1632937 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

J.O. Aho wrote:
> Evil Otto wrote:
>
>> Put session_start() in the functions that get called after the initial
>> pageload. Just generates warnings that a session has already been
>> started (by the original pageload).
>
> You are supposed to use one session_start() per script, say your AJAX
> will call the getnewcars.php to get a result, then you have
> session_start() first in that script, and thats all, nothing in the
> functions that are called from that script.
>

You can put session_start() after other output if you use ob_start to
buffer output.
turnitup [ So, 18 Februar 2007 17:16 ] [ ID #1632943 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

turnitup wrote:
> J.O. Aho wrote:
>> Evil Otto wrote:
>>
>>> Put session_start() in the functions that get called after the initial
>>> pageload. Just generates warnings that a session has already been
>>> started (by the original pageload).
>>
>> You are supposed to use one session_start() per script, say your AJAX
>> will call the getnewcars.php to get a result, then you have
>> session_start() first in that script, and thats all, nothing in the
>> functions that are called from that script.
>>
>
> You can put session_start() after other output if you use ob_start to
> buffer output.

Even if using buffering, it's a good thing to write it properly anyway.

--

//Aho
Shion [ So, 18 Februar 2007 17:51 ] [ ID #1632945 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

There's no output going to the browser before session_start(). The
top of my script looks like this:

--quote

<?php
error_reporting(E_ALL);
ini_set("display_errors","1");
?>

<?php


/* Should only be debugging from one machine
* Should plan on making this a config variable
*/

if ($_SERVER['REMOTE_ADDR'] == '192.168.1.201')
{
$debug = 1;
}
$html='';

require_once('includes.php');
session_start();

--end quote

After that, there is content that is put into a variable and then run
through a filter before it gets echoed to the browser. There's an
onLoad="" call in the body tag that trips off another request, which
generates content that includes a link, as well as setting a $_SESSION
variable in the process. The problem is that it doesn't appear to
"write" the variable out to the session storage, because subsequent
requests can't see it.

On Feb 17, 10:23 pm, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
> Evil Otto wrote:
> > My page loads, and calls an init() function that returns content to a
> > div on the page, as well as setting a $_SESSION variable. The content
> > it returns includes a link that calls the same variable, but I get an
> > error that says the index isn't defined.
>
> > The second two calls are AJAX-generated. The second call immediately
> > echos the $_SESSION variable back after it sets it, and it sets it
> > properly. But the subsequent request doesn't see it.
>
> > I can't figure this one out, and this sort of function is vital to the
> > site I'm building.
>
> > Things I've already done:
>
> > Put session_start() in the functions that get called after the initial
> > pageload. Just generates warnings that a session has already been
> > started (by the original pageload).
>
> > Checked to make sure the same session is being used by all requests,
> > and it is (according to session_id).
>
> > Any help is appreciated.
>
> session_start() must be called before ANY OUTPUT - including whitespace,
> DOCTYPE statement, <head>, etc. 99% of the time people ask about
> session problems here, they have already sent output before the call to
> session_start() is made, but don't have error reporting enabled.
>
> As the very first lines in the page you're loading, try the following:
>
> <?php
> error_reporting(E_ALL);
> ini_set("display_errors","1");
> ?>
>
> No whitespace or anything else before it.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck... [at] attglobal.net
> ==================
zburnham [ So, 18 Februar 2007 21:09 ] [ ID #1632947 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

Evil Otto kirjoitti:
> There's no output going to the browser before session_start(). The
> top of my script looks like this:
>
> --quote
>
> <?php
> error_reporting(E_ALL);
> ini_set("display_errors","1");
> ?>

Output starts here cos you have a gap between two php tags. It's the
whitespace effect.

> <?php
>


--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
spam [at] outolempi.net | Gedoon-S [at] IRCnet | rot13(xvzzb [at] bhgbyrzcv.arg)
Kimmo Laine [ So, 18 Februar 2007 21:24 ] [ ID #1632949 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

I removed the ?> and <?php tags from where you saw the whitespace, so
there's no extraneous whitespace. Had no effect on the problem I'm
seeing; the third request still cannot see changes to the $_SESSION
variable made by the second.

On Feb 18, 3:24 pm, Kimmo Laine <s... [at] outolempi.net> wrote:
> Evil Otto kirjoitti:
>
> > There's no output going to the browser before session_start(). The
> > top of my script looks like this:
>
> > --quote
>
> > <?php
> > error_reporting(E_ALL);
> > ini_set("display_errors","1");
> > ?>
>
> Output starts here cos you have a gap between two php tags. It's the
> whitespace effect.
>
> > <?php
>
> >
>
> --
> "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
> s... [at] outolempi.net | Gedoon-S [at] IRCnet | rot13(x... [at] bhgbyrzcv.arg)
zburnham [ So, 18 Februar 2007 21:45 ] [ ID #1632951 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

Evil Otto wrote:
> My page loads, and calls an init() function that returns content to a
> div on the page, as well as setting a $_SESSION variable. The content
> it returns includes a link that calls the same variable, but I get an
> error that says the index isn't defined.
>
> The second two calls are AJAX-generated. The second call immediately
> echos the $_SESSION variable back after it sets it, and it sets it
> properly. But the subsequent request doesn't see it.
>
> I can't figure this one out, and this sort of function is vital to the
> site I'm building.
>
> Things I've already done:
>
> Put session_start() in the functions that get called after the initial
> pageload. Just generates warnings that a session has already been
> started (by the original pageload).
>
> Checked to make sure the same session is being used by all requests,
> and it is (according to session_id).
>
> Any help is appreciated.
>

session_start() must be called before ANY OUTPUT - including whitespace,
DOCTYPE statement, <head>, etc. 99% of the time people ask about
session problems here, they have already sent output before the call to
session_start() is made, but don't have error reporting enabled.

As the very first lines in the page you're loading, try the following:

<?php
error_reporting(E_ALL);
ini_set("display_errors","1");
?>

No whitespace or anything else before it.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex [at] attglobal.net
==================
Jerry Stuckle [ So, 18 Februar 2007 04:23 ] [ ID #1632968 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

Evil Otto wrote:

> Put session_start() in the functions that get called after the initial
> pageload. Just generates warnings that a session has already been
> started (by the original pageload).

You are supposed to use one session_start() per script, say your AJAX will
call the getnewcars.php to get a result, then you have session_start() first
in that script, and thats all, nothing in the functions that are called from
that script.

--

//Aho
Shion [ So, 18 Februar 2007 09:38 ] [ ID #1632981 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

J.O. Aho wrote:
> Evil Otto wrote:
>
>> Put session_start() in the functions that get called after the initial
>> pageload. Just generates warnings that a session has already been
>> started (by the original pageload).
>
> You are supposed to use one session_start() per script, say your AJAX
> will call the getnewcars.php to get a result, then you have
> session_start() first in that script, and thats all, nothing in the
> functions that are called from that script.
>

You can put session_start() after other output if you use ob_start to
buffer output.
turnitup [ So, 18 Februar 2007 17:16 ] [ ID #1633000 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

turnitup wrote:
> J.O. Aho wrote:
>> Evil Otto wrote:
>>
>>> Put session_start() in the functions that get called after the initial
>>> pageload. Just generates warnings that a session has already been
>>> started (by the original pageload).
>>
>> You are supposed to use one session_start() per script, say your AJAX
>> will call the getnewcars.php to get a result, then you have
>> session_start() first in that script, and thats all, nothing in the
>> functions that are called from that script.
>>
>
> You can put session_start() after other output if you use ob_start to
> buffer output.

Even if using buffering, it's a good thing to write it properly anyway.

--

//Aho
Shion [ So, 18 Februar 2007 17:51 ] [ ID #1633006 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

There's no output going to the browser before session_start(). The
top of my script looks like this:

--quote

<?php
error_reporting(E_ALL);
ini_set("display_errors","1");
?>

<?php


/* Should only be debugging from one machine
* Should plan on making this a config variable
*/

if ($_SERVER['REMOTE_ADDR'] == '192.168.1.201')
{
$debug = 1;
}
$html='';

require_once('includes.php');
session_start();

--end quote

After that, there is content that is put into a variable and then run
through a filter before it gets echoed to the browser. There's an
onLoad="" call in the body tag that trips off another request, which
generates content that includes a link, as well as setting a $_SESSION
variable in the process. The problem is that it doesn't appear to
"write" the variable out to the session storage, because subsequent
requests can't see it.

On Feb 17, 10:23 pm, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
> Evil Otto wrote:
> > My page loads, and calls an init() function that returns content to a
> > div on the page, as well as setting a $_SESSION variable. The content
> > it returns includes a link that calls the same variable, but I get an
> > error that says the index isn't defined.
>
> > The second two calls are AJAX-generated. The second call immediately
> > echos the $_SESSION variable back after it sets it, and it sets it
> > properly. But the subsequent request doesn't see it.
>
> > I can't figure this one out, and this sort of function is vital to the
> > site I'm building.
>
> > Things I've already done:
>
> > Put session_start() in the functions that get called after the initial
> > pageload. Just generates warnings that a session has already been
> > started (by the original pageload).
>
> > Checked to make sure the same session is being used by all requests,
> > and it is (according to session_id).
>
> > Any help is appreciated.
>
> session_start() must be called before ANY OUTPUT - including whitespace,
> DOCTYPE statement, <head>, etc. 99% of the time people ask about
> session problems here, they have already sent output before the call to
> session_start() is made, but don't have error reporting enabled.
>
> As the very first lines in the page you're loading, try the following:
>
> <?php
> error_reporting(E_ALL);
> ini_set("display_errors","1");
> ?>
>
> No whitespace or anything else before it.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck... [at] attglobal.net
> ==================
zburnham [ So, 18 Februar 2007 21:09 ] [ ID #1633014 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

Evil Otto kirjoitti:
> There's no output going to the browser before session_start(). The
> top of my script looks like this:
>
> --quote
>
> <?php
> error_reporting(E_ALL);
> ini_set("display_errors","1");
> ?>

Output starts here cos you have a gap between two php tags. It's the
whitespace effect.

> <?php
>


--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
spam [at] outolempi.net | Gedoon-S [at] IRCnet | rot13(xvzzb [at] bhgbyrzcv.arg)
Kimmo Laine [ So, 18 Februar 2007 21:24 ] [ ID #1633017 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

I removed the ?> and <?php tags from where you saw the whitespace, so
there's no extraneous whitespace. Had no effect on the problem I'm
seeing; the third request still cannot see changes to the $_SESSION
variable made by the second.

On Feb 18, 3:24 pm, Kimmo Laine <s... [at] outolempi.net> wrote:
> Evil Otto kirjoitti:
>
> > There's no output going to the browser before session_start(). The
> > top of my script looks like this:
>
> > --quote
>
> > <?php
> > error_reporting(E_ALL);
> > ini_set("display_errors","1");
> > ?>
>
> Output starts here cos you have a gap between two php tags. It's the
> whitespace effect.
>
> > <?php
>
> >
>
> --
> "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
> s... [at] outolempi.net | Gedoon-S [at] IRCnet | rot13(x... [at] bhgbyrzcv.arg)
zburnham [ So, 18 Februar 2007 21:45 ] [ ID #1633019 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

Evil Otto wrote:
> I removed the ?> and <?php tags from where you saw the whitespace, so
> there's no extraneous whitespace. Had no effect on the problem I'm
> seeing; the third request still cannot see changes to the $_SESSION
> variable made by the second.
>
> On Feb 18, 3:24 pm, Kimmo Laine <s... [at] outolempi.net> wrote:
>> Evil Otto kirjoitti:
>>
>>> There's no output going to the browser before session_start(). The
>>> top of my script looks like this:
>>> --quote
>>> <?php
>>> error_reporting(E_ALL);
>>> ini_set("display_errors","1");
>>> ?>
>> Output starts here cos you have a gap between two php tags. It's the
>> whitespace effect.
>>
>>> <?php
>> >
>>
>> --
>> "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
>> s... [at] outolempi.net | Gedoon-S [at] IRCnet | rot13(x... [at] bhgbyrzcv.arg)
>
>

And can you be sure that *NOTHING* in your include.php file generates
output - including leading or trailing blanks, newline characters, etc.?

What do you get for error messages?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex [at] attglobal.net
==================
Jerry Stuckle [ Mo, 19 Februar 2007 02:37 ] [ ID #1633849 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

turnitup wrote:
> J.O. Aho wrote:
>> Evil Otto wrote:
>>
>>> Put session_start() in the functions that get called after the initial
>>> pageload. Just generates warnings that a session has already been
>>> started (by the original pageload).
>>
>> You are supposed to use one session_start() per script, say your AJAX
>> will call the getnewcars.php to get a result, then you have
>> session_start() first in that script, and thats all, nothing in the
>> functions that are called from that script.
>>
>
> You can put session_start() after other output if you use ob_start to
> buffer output.

Output buffering just hides the real problem - it doesn't solve it.



--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex [at] attglobal.net
==================
Jerry Stuckle [ Mo, 19 Februar 2007 02:37 ] [ ID #1633850 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

The only error i get is an undefined index message when the third
request tries to access the $_SESSION variable.

On Feb 18, 8:37 pm, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
> Evil Otto wrote:
> > I removed the ?> and <?php tags from where you saw the whitespace, so
> > there's no extraneous whitespace. Had no effect on the problem I'm
> > seeing; the third request still cannot see changes to the $_SESSION
> > variable made by the second.
>
> > On Feb 18, 3:24 pm, Kimmo Laine <s... [at] outolempi.net> wrote:
> >> Evil Otto kirjoitti:
>
> >>> There's no output going to the browser before session_start(). The
> >>> top of my script looks like this:
> >>> --quote
> >>> <?php
> >>> error_reporting(E_ALL);
> >>> ini_set("display_errors","1");
> >>> ?>
> >> Output starts here cos you have a gap between two php tags. It's the
> >> whitespace effect.
>
> >>> <?php
>
> >> --
> >> "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
> >> s... [at] outolempi.net | Gedoon-S [at] IRCnet | rot13(x... [at] bhgbyrzcv.arg)
>
> And can you be sure that *NOTHING* in your include.php file generates
> output - including leading or trailing blanks, newline characters, etc.?
>
> What do you get for error messages?
>
> --
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck... [at] attglobal.net
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
zburnham [ Mo, 19 Februar 2007 03:16 ] [ ID #1633851 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

On Feb 18, 8:37 pm, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
> Evil Otto wrote:
> > I removed the ?> and <?php tags from where you saw the whitespace, so
> > there's no extraneous whitespace. Had no effect on the problem I'm
> > seeing; the third request still cannot see changes to the $_SESSION
> > variable made by the second.
>
> > On Feb 18, 3:24 pm, Kimmo Laine <s... [at] outolempi.net> wrote:
> >> Evil Otto kirjoitti:
>
> >>> There's no output going to the browser before session_start(). The
> >>> top of my script looks like this:
> >>> --quote
> >>> <?php
> >>> error_reporting(E_ALL);
> >>> ini_set("display_errors","1");
> >>> ?>
> >> Output starts here cos you have a gap between two php tags. It's the
> >> whitespace effect.
>
> >>> <?php
>
> >> --
> >> "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
Positive.

> >> s... [at] outolempi.net | Gedoon-S [at] IRCnet | rot13(x... [at] bhgbyrzcv.arg)
>
> And can you be sure that *NOTHING* in your include.php file generates
> output - including leading or trailing blanks, newline characters, etc.?
>
> What do you get for error messages?
>
> --
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck... [at] attglobal.net
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
zburnham [ Mo, 19 Februar 2007 03:17 ] [ ID #1633852 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

Evil Otto wrote:
> The only error i get is an undefined index message when the third
> request tries to access the $_SESSION variable.
>
> On Feb 18, 8:37 pm, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
>> Evil Otto wrote:
>>> I removed the ?> and <?php tags from where you saw the whitespace, so
>>> there's no extraneous whitespace. Had no effect on the problem I'm
>>> seeing; the third request still cannot see changes to the $_SESSION
>>> variable made by the second.
>>> On Feb 18, 3:24 pm, Kimmo Laine <s... [at] outolempi.net> wrote:
>>>> Evil Otto kirjoitti:
>>>>> There's no output going to the browser before session_start(). The
>>>>> top of my script looks like this:
>>>>> --quote
>>>>> <?php
>>>>> error_reporting(E_ALL);
>>>>> ini_set("display_errors","1");
>>>>> ?>
>>>> Output starts here cos you have a gap between two php tags. It's the
>>>> whitespace effect.
>>>>> <?php
>>>> --
>>>> "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
>>>> s... [at] outolempi.net | Gedoon-S [at] IRCnet | rot13(x... [at] bhgbyrzcv.arg)
>> And can you be sure that *NOTHING* in your include.php file generates
>> output - including leading or trailing blanks, newline characters, etc.?
>>
>> What do you get for error messages?
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck... [at] attglobal.net
>> ==================
>
>

In that case there are only two options. Either the second page didn't
call session_start() before any output, or the third page didn't do it.

Sessions work. If the second page properly starts the session and sets
the session info, and the third page properly starts the session, it
does work.

I know this sounds blunt - and I'm really sorry, I don't mean to be
blunt about it. But sessions do work. If you have a case where the
second page sets a session variable and the third page can't read it,
one of two things is wrong:

1. The second page didn't actually set the $_SESSION value in the
session (possibly because session_start wasn't called early enough - but
there could be other reasons), or
2. The third page can't read the $_SESSION value. In this case if it
is set, about the only option you have is that session_start() wasn't
called soon enough.

So, if the third page (where the value is read) is correct, perhaps the
second page (where it is set) has a problem?

It's got to be one or the other.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex [at] attglobal.net
==================
Jerry Stuckle [ Mo, 19 Februar 2007 03:40 ] [ ID #1633854 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

session_start() is called exactly once, at the beginning of the main
script.

There are multiple requests, but there is ONE page.

I've tried putting session_start() at the beginning of the functions
that get called, but they throw "session has already been started"
errors.



On Feb 18, 9:40 pm, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
> Evil Otto wrote:
> > The only error i get is an undefined index message when the third
> > request tries to access the $_SESSION variable.
>
> > On Feb 18, 8:37 pm, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
> >> Evil Otto wrote:
> >>> I removed the ?> and <?php tags from where you saw the whitespace, so
> >>> there's no extraneous whitespace. Had no effect on the problem I'm
> >>> seeing; the third request still cannot see changes to the $_SESSION
> >>> variable made by the second.
> >>> On Feb 18, 3:24 pm, Kimmo Laine <s... [at] outolempi.net> wrote:
> >>>> Evil Otto kirjoitti:
> >>>>> There's no output going to the browser before session_start(). The
> >>>>> top of my script looks like this:
> >>>>> --quote
> >>>>> <?php
> >>>>> error_reporting(E_ALL);
> >>>>> ini_set("display_errors","1");
> >>>>> ?>
> >>>> Output starts here cos you have a gap between two php tags. It's the
> >>>> whitespace effect.
> >>>>> <?php
> >>>> --
> >>>> "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirvi=
ö
> >>>> s... [at] outolempi.net | Gedoon-S [at] IRCnet | rot13(x... [at] bhgbyrzcv.arg)
> >> And can you be sure that *NOTHING* in your include.php file generates
> >> output - including leading or trailing blanks, newline characters, etc=
..?
>
> >> What do you get for error messages?
>
> >> --
> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> >> Remove the "x" from my email address
> >> Jerry Stuckle
> >> JDS Computer Training Corp.
> >> jstuck... [at] attglobal.net
> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>
> In that case there are only two options. Either the second page didn't
> call session_start() before any output, or the third page didn't do it.
>
> Sessions work. If the second page properly starts the session and sets
> the session info, and the third page properly starts the session, it
> does work.
>
> I know this sounds blunt - and I'm really sorry, I don't mean to be
> blunt about it. But sessions do work. If you have a case where the
> second page sets a session variable and the third page can't read it,
> one of two things is wrong:
>
> 1. The second page didn't actually set the $_SESSION value in the
> session (possibly because session_start wasn't called early enough - but
> there could be other reasons), or
> 2. The third page can't read the $_SESSION value. In this case if it
> is set, about the only option you have is that session_start() wasn't
> called soon enough.
>
> So, if the third page (where the value is read) is correct, perhaps the
> second page (where it is set) has a problem?
>
> It's got to be one or the other.
>
> --
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck... [at] attglobal.net
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
zburnham [ Mo, 19 Februar 2007 04:32 ] [ ID #1633856 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

Evil Otto wrote:
> session_start() is called exactly once, at the beginning of the main
> script.
>
> There are multiple requests, but there is ONE page.
>
> I've tried putting session_start() at the beginning of the functions
> that get called, but they throw "session has already been started"
> errors.
>
>
>
> On Feb 18, 9:40 pm, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
>> Evil Otto wrote:
>>> The only error i get is an undefined index message when the third
>>> request tries to access the $_SESSION variable.
>>> On Feb 18, 8:37 pm, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
>>>> Evil Otto wrote:
>>>>> I removed the ?> and <?php tags from where you saw the whitespace, so
>>>>> there's no extraneous whitespace. Had no effect on the problem I'm
>>>>> seeing; the third request still cannot see changes to the $_SESSION
>>>>> variable made by the second.
>>>>> On Feb 18, 3:24 pm, Kimmo Laine <s... [at] outolempi.net> wrote:
>>>>>> Evil Otto kirjoitti:
>>>>>>> There's no output going to the browser before session_start(). The
>>>>>>> top of my script looks like this:
>>>>>>> --quote
>>>>>>> <?php
>>>>>>> error_reporting(E_ALL);
>>>>>>> ini_set("display_errors","1");
>>>>>>> ?>
>>>>>> Output starts here cos you have a gap between two php tags. It's the
>>>>>> whitespace effect.
>>>>>>> <?php
>>>>>> --
>>>>>> "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
>>>>>> s... [at] outolempi.net | Gedoon-S [at] IRCnet | rot13(x... [at] bhgbyrzcv.arg)
>>>> And can you be sure that *NOTHING* in your include.php file generates
>>>> output - including leading or trailing blanks, newline characters, etc.?
>>>> What do you get for error messages?
>>>> --
>>>> ==================
>>>> Remove the "x" from my email address
>>>> Jerry Stuckle
>>>> JDS Computer Training Corp.
>>>> jstuck... [at] attglobal.net
>>>> ==================
>> In that case there are only two options. Either the second page didn't
>> call session_start() before any output, or the third page didn't do it.
>>
>> Sessions work. If the second page properly starts the session and sets
>> the session info, and the third page properly starts the session, it
>> does work.
>>
>> I know this sounds blunt - and I'm really sorry, I don't mean to be
>> blunt about it. But sessions do work. If you have a case where the
>> second page sets a session variable and the third page can't read it,
>> one of two things is wrong:
>>
>> 1. The second page didn't actually set the $_SESSION value in the
>> session (possibly because session_start wasn't called early enough - but
>> there could be other reasons), or
>> 2. The third page can't read the $_SESSION value. In this case if it
>> is set, about the only option you have is that session_start() wasn't
>> called soon enough.
>>
>> So, if the third page (where the value is read) is correct, perhaps the
>> second page (where it is set) has a problem?
>>
>> It's got to be one or the other.
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck... [at] attglobal.net
>> ==================
>
>

Hmmm, when you say

"The content it returns includes a link that calls the same variable,
but I get an error that says the index isn't defined."

what do you mean exactly? Is this an html link? A function call?


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex [at] attglobal.net
==================
Jerry Stuckle [ Mo, 19 Februar 2007 13:24 ] [ ID #1633864 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

On Feb 19, 7:24 am, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
> Evil Otto wrote:
> > session_start() is called exactly once, at the beginning of the main
> > script.
>
> > There are multiple requests, but there is ONE page.
>
> > I've tried putting session_start() at the beginning of the functions
> > that get called, but they throw "session has already been started"
> > errors.
>
> > On Feb 18, 9:40 pm, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
> >> Evil Otto wrote:
> >>> The only error i get is an undefined index message when the third
> >>> request tries to access the $_SESSION variable.
> >>> On Feb 18, 8:37 pm, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
> >>>> Evil Otto wrote:
> >>>>> I removed the ?> and <?php tags from where you saw the whitespace, =
so
> >>>>> there's no extraneous whitespace. Had no effect on the problem I'm
> >>>>> seeing; the third request still cannot see changes to the $_SESSION
> >>>>> variable made by the second.
> >>>>> On Feb 18, 3:24 pm, Kimmo Laine <s... [at] outolempi.net> wrote:
> >>>>>> Evil Otto kirjoitti:
> >>>>>>> There's no output going to the browser before session_start(). T=
he
> >>>>>>> top of my script looks like this:
> >>>>>>> --quote
> >>>>>>> <?php
> >>>>>>> error_reporting(E_ALL);
> >>>>>>> ini_set("display_errors","1");
> >>>>>>> ?>
> >>>>>> Output starts here cos you have a gap between two php tags. It's t=
he
> >>>>>> whitespace effect.
> >>>>>>> <?php
> >>>>>> --
> >>>>>> "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirv=

> >>>>>> s... [at] outolempi.net | Gedoon-S [at] IRCnet | rot13(x... [at] bhgbyrzcv.arg)
> >>>> And can you be sure that *NOTHING* in your include.php file generates
> >>>> output - including leading or trailing blanks, newline characters, e=
tc.?
> >>>> What do you get for error messages?
> >>>> --
> >>>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> >>>> Remove the "x" from my email address
> >>>> Jerry Stuckle
> >>>> JDS Computer Training Corp.
> >>>> jstuck... [at] attglobal.net
> >>>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> >> In that case there are only two options. Either the second page didn't
> >> call session_start() before any output, or the third page didn't do it.
>
> >> Sessions work. If the second page properly starts the session and sets
> >> the session info, and the third page properly starts the session, it
> >> does work.
>
> >> I know this sounds blunt - and I'm really sorry, I don't mean to be
> >> blunt about it. But sessions do work. If you have a case where the
> >> second page sets a session variable and the third page can't read it,
> >> one of two things is wrong:
>
> >> 1. The second page didn't actually set the $_SESSION value in the
> >> session (possibly because session_start wasn't called early enough - b=
ut
> >> there could be other reasons), or
> >> 2. The third page can't read the $_SESSION value. In this case if it
> >> is set, about the only option you have is that session_start() wasn't
> >> called soon enough.
>
> >> So, if the third page (where the value is read) is correct, perhaps the
> >> second page (where it is set) has a problem?
>
> >> It's got to be one or the other.
>
> >> --
> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> >> Remove the "x" from my email address
> >> Jerry Stuckle
> >> JDS Computer Training Corp.
> >> jstuck... [at] attglobal.net
> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>
> Hmmm, when you say
>
> "The content it returns includes a link that calls the same variable,
> but I get an error that says the index isn't defined."
>
> what do you mean exactly? Is this an html link? A function call?
>
> --
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck... [at] attglobal.net
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

This is an onClick attribute in a div that calls a javascript
function, which makes an Ajax request calling a PHP funciton on the
server.

I think i may have cleared this up, however. Turns out a
session_destroy() was in the wrong place, and an undefined index
should have been expected.
zburnham [ Mo, 19 Februar 2007 19:10 ] [ ID #1633870 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

Evil Otto wrote:
> I removed the ?> and <?php tags from where you saw the whitespace, so
> there's no extraneous whitespace. Had no effect on the problem I'm
> seeing; the third request still cannot see changes to the $_SESSION
> variable made by the second.
>
> On Feb 18, 3:24 pm, Kimmo Laine <s... [at] outolempi.net> wrote:
>> Evil Otto kirjoitti:
>>
>>> There's no output going to the browser before session_start(). The
>>> top of my script looks like this:
>>> --quote
>>> <?php
>>> error_reporting(E_ALL);
>>> ini_set("display_errors","1");
>>> ?>
>> Output starts here cos you have a gap between two php tags. It's the
>> whitespace effect.
>>
>>> <?php
>> >
>>
>> --
>> "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
>> s... [at] outolempi.net | Gedoon-S [at] IRCnet | rot13(x... [at] bhgbyrzcv.arg)
>
>

And can you be sure that *NOTHING* in your include.php file generates
output - including leading or trailing blanks, newline characters, etc.?

What do you get for error messages?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex [at] attglobal.net
==================
Jerry Stuckle [ Mo, 19 Februar 2007 02:37 ] [ ID #1633891 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

turnitup wrote:
> J.O. Aho wrote:
>> Evil Otto wrote:
>>
>>> Put session_start() in the functions that get called after the initial
>>> pageload. Just generates warnings that a session has already been
>>> started (by the original pageload).
>>
>> You are supposed to use one session_start() per script, say your AJAX
>> will call the getnewcars.php to get a result, then you have
>> session_start() first in that script, and thats all, nothing in the
>> functions that are called from that script.
>>
>
> You can put session_start() after other output if you use ob_start to
> buffer output.

Output buffering just hides the real problem - it doesn't solve it.



--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex [at] attglobal.net
==================
Jerry Stuckle [ Mo, 19 Februar 2007 02:37 ] [ ID #1633892 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

The only error i get is an undefined index message when the third
request tries to access the $_SESSION variable.

On Feb 18, 8:37 pm, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
> Evil Otto wrote:
> > I removed the ?> and <?php tags from where you saw the whitespace, so
> > there's no extraneous whitespace. Had no effect on the problem I'm
> > seeing; the third request still cannot see changes to the $_SESSION
> > variable made by the second.
>
> > On Feb 18, 3:24 pm, Kimmo Laine <s... [at] outolempi.net> wrote:
> >> Evil Otto kirjoitti:
>
> >>> There's no output going to the browser before session_start(). The
> >>> top of my script looks like this:
> >>> --quote
> >>> <?php
> >>> error_reporting(E_ALL);
> >>> ini_set("display_errors","1");
> >>> ?>
> >> Output starts here cos you have a gap between two php tags. It's the
> >> whitespace effect.
>
> >>> <?php
>
> >> --
> >> "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
> >> s... [at] outolempi.net | Gedoon-S [at] IRCnet | rot13(x... [at] bhgbyrzcv.arg)
>
> And can you be sure that *NOTHING* in your include.php file generates
> output - including leading or trailing blanks, newline characters, etc.?
>
> What do you get for error messages?
>
> --
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck... [at] attglobal.net
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
zburnham [ Mo, 19 Februar 2007 03:16 ] [ ID #1633893 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

On Feb 18, 8:37 pm, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
> Evil Otto wrote:
> > I removed the ?> and <?php tags from where you saw the whitespace, so
> > there's no extraneous whitespace. Had no effect on the problem I'm
> > seeing; the third request still cannot see changes to the $_SESSION
> > variable made by the second.
>
> > On Feb 18, 3:24 pm, Kimmo Laine <s... [at] outolempi.net> wrote:
> >> Evil Otto kirjoitti:
>
> >>> There's no output going to the browser before session_start(). The
> >>> top of my script looks like this:
> >>> --quote
> >>> <?php
> >>> error_reporting(E_ALL);
> >>> ini_set("display_errors","1");
> >>> ?>
> >> Output starts here cos you have a gap between two php tags. It's the
> >> whitespace effect.
>
> >>> <?php
>
> >> --
> >> "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
Positive.

> >> s... [at] outolempi.net | Gedoon-S [at] IRCnet | rot13(x... [at] bhgbyrzcv.arg)
>
> And can you be sure that *NOTHING* in your include.php file generates
> output - including leading or trailing blanks, newline characters, etc.?
>
> What do you get for error messages?
>
> --
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck... [at] attglobal.net
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
zburnham [ Mo, 19 Februar 2007 03:17 ] [ ID #1633894 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

Evil Otto wrote:
> The only error i get is an undefined index message when the third
> request tries to access the $_SESSION variable.
>
> On Feb 18, 8:37 pm, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
>> Evil Otto wrote:
>>> I removed the ?> and <?php tags from where you saw the whitespace, so
>>> there's no extraneous whitespace. Had no effect on the problem I'm
>>> seeing; the third request still cannot see changes to the $_SESSION
>>> variable made by the second.
>>> On Feb 18, 3:24 pm, Kimmo Laine <s... [at] outolempi.net> wrote:
>>>> Evil Otto kirjoitti:
>>>>> There's no output going to the browser before session_start(). The
>>>>> top of my script looks like this:
>>>>> --quote
>>>>> <?php
>>>>> error_reporting(E_ALL);
>>>>> ini_set("display_errors","1");
>>>>> ?>
>>>> Output starts here cos you have a gap between two php tags. It's the
>>>> whitespace effect.
>>>>> <?php
>>>> --
>>>> "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
>>>> s... [at] outolempi.net | Gedoon-S [at] IRCnet | rot13(x... [at] bhgbyrzcv.arg)
>> And can you be sure that *NOTHING* in your include.php file generates
>> output - including leading or trailing blanks, newline characters, etc.?
>>
>> What do you get for error messages?
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck... [at] attglobal.net
>> ==================
>
>

In that case there are only two options. Either the second page didn't
call session_start() before any output, or the third page didn't do it.

Sessions work. If the second page properly starts the session and sets
the session info, and the third page properly starts the session, it
does work.

I know this sounds blunt - and I'm really sorry, I don't mean to be
blunt about it. But sessions do work. If you have a case where the
second page sets a session variable and the third page can't read it,
one of two things is wrong:

1. The second page didn't actually set the $_SESSION value in the
session (possibly because session_start wasn't called early enough - but
there could be other reasons), or
2. The third page can't read the $_SESSION value. In this case if it
is set, about the only option you have is that session_start() wasn't
called soon enough.

So, if the third page (where the value is read) is correct, perhaps the
second page (where it is set) has a problem?

It's got to be one or the other.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex [at] attglobal.net
==================
Jerry Stuckle [ Mo, 19 Februar 2007 03:40 ] [ ID #1633896 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

session_start() is called exactly once, at the beginning of the main
script.

There are multiple requests, but there is ONE page.

I've tried putting session_start() at the beginning of the functions
that get called, but they throw "session has already been started"
errors.



On Feb 18, 9:40 pm, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
> Evil Otto wrote:
> > The only error i get is an undefined index message when the third
> > request tries to access the $_SESSION variable.
>
> > On Feb 18, 8:37 pm, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
> >> Evil Otto wrote:
> >>> I removed the ?> and <?php tags from where you saw the whitespace, so
> >>> there's no extraneous whitespace. Had no effect on the problem I'm
> >>> seeing; the third request still cannot see changes to the $_SESSION
> >>> variable made by the second.
> >>> On Feb 18, 3:24 pm, Kimmo Laine <s... [at] outolempi.net> wrote:
> >>>> Evil Otto kirjoitti:
> >>>>> There's no output going to the browser before session_start(). The
> >>>>> top of my script looks like this:
> >>>>> --quote
> >>>>> <?php
> >>>>> error_reporting(E_ALL);
> >>>>> ini_set("display_errors","1");
> >>>>> ?>
> >>>> Output starts here cos you have a gap between two php tags. It's the
> >>>> whitespace effect.
> >>>>> <?php
> >>>> --
> >>>> "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirvi=
ö
> >>>> s... [at] outolempi.net | Gedoon-S [at] IRCnet | rot13(x... [at] bhgbyrzcv.arg)
> >> And can you be sure that *NOTHING* in your include.php file generates
> >> output - including leading or trailing blanks, newline characters, etc=
..?
>
> >> What do you get for error messages?
>
> >> --
> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> >> Remove the "x" from my email address
> >> Jerry Stuckle
> >> JDS Computer Training Corp.
> >> jstuck... [at] attglobal.net
> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>
> In that case there are only two options. Either the second page didn't
> call session_start() before any output, or the third page didn't do it.
>
> Sessions work. If the second page properly starts the session and sets
> the session info, and the third page properly starts the session, it
> does work.
>
> I know this sounds blunt - and I'm really sorry, I don't mean to be
> blunt about it. But sessions do work. If you have a case where the
> second page sets a session variable and the third page can't read it,
> one of two things is wrong:
>
> 1. The second page didn't actually set the $_SESSION value in the
> session (possibly because session_start wasn't called early enough - but
> there could be other reasons), or
> 2. The third page can't read the $_SESSION value. In this case if it
> is set, about the only option you have is that session_start() wasn't
> called soon enough.
>
> So, if the third page (where the value is read) is correct, perhaps the
> second page (where it is set) has a problem?
>
> It's got to be one or the other.
>
> --
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck... [at] attglobal.net
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
zburnham [ Mo, 19 Februar 2007 04:32 ] [ ID #1633897 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

Evil Otto wrote:
> session_start() is called exactly once, at the beginning of the main
> script.
>
> There are multiple requests, but there is ONE page.
>
> I've tried putting session_start() at the beginning of the functions
> that get called, but they throw "session has already been started"
> errors.
>
>
>
> On Feb 18, 9:40 pm, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
>> Evil Otto wrote:
>>> The only error i get is an undefined index message when the third
>>> request tries to access the $_SESSION variable.
>>> On Feb 18, 8:37 pm, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
>>>> Evil Otto wrote:
>>>>> I removed the ?> and <?php tags from where you saw the whitespace, so
>>>>> there's no extraneous whitespace. Had no effect on the problem I'm
>>>>> seeing; the third request still cannot see changes to the $_SESSION
>>>>> variable made by the second.
>>>>> On Feb 18, 3:24 pm, Kimmo Laine <s... [at] outolempi.net> wrote:
>>>>>> Evil Otto kirjoitti:
>>>>>>> There's no output going to the browser before session_start(). The
>>>>>>> top of my script looks like this:
>>>>>>> --quote
>>>>>>> <?php
>>>>>>> error_reporting(E_ALL);
>>>>>>> ini_set("display_errors","1");
>>>>>>> ?>
>>>>>> Output starts here cos you have a gap between two php tags. It's the
>>>>>> whitespace effect.
>>>>>>> <?php
>>>>>> --
>>>>>> "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
>>>>>> s... [at] outolempi.net | Gedoon-S [at] IRCnet | rot13(x... [at] bhgbyrzcv.arg)
>>>> And can you be sure that *NOTHING* in your include.php file generates
>>>> output - including leading or trailing blanks, newline characters, etc.?
>>>> What do you get for error messages?
>>>> --
>>>> ==================
>>>> Remove the "x" from my email address
>>>> Jerry Stuckle
>>>> JDS Computer Training Corp.
>>>> jstuck... [at] attglobal.net
>>>> ==================
>> In that case there are only two options. Either the second page didn't
>> call session_start() before any output, or the third page didn't do it.
>>
>> Sessions work. If the second page properly starts the session and sets
>> the session info, and the third page properly starts the session, it
>> does work.
>>
>> I know this sounds blunt - and I'm really sorry, I don't mean to be
>> blunt about it. But sessions do work. If you have a case where the
>> second page sets a session variable and the third page can't read it,
>> one of two things is wrong:
>>
>> 1. The second page didn't actually set the $_SESSION value in the
>> session (possibly because session_start wasn't called early enough - but
>> there could be other reasons), or
>> 2. The third page can't read the $_SESSION value. In this case if it
>> is set, about the only option you have is that session_start() wasn't
>> called soon enough.
>>
>> So, if the third page (where the value is read) is correct, perhaps the
>> second page (where it is set) has a problem?
>>
>> It's got to be one or the other.
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck... [at] attglobal.net
>> ==================
>
>

Hmmm, when you say

"The content it returns includes a link that calls the same variable,
but I get an error that says the index isn't defined."

what do you mean exactly? Is this an html link? A function call?


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex [at] attglobal.net
==================
Jerry Stuckle [ Mo, 19 Februar 2007 13:24 ] [ ID #1633917 ]

Re: Can't read $_SESSION variables set by previous request, AJAX

On Feb 19, 7:24 am, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
> Evil Otto wrote:
> > session_start() is called exactly once, at the beginning of the main
> > script.
>
> > There are multiple requests, but there is ONE page.
>
> > I've tried putting session_start() at the beginning of the functions
> > that get called, but they throw "session has already been started"
> > errors.
>
> > On Feb 18, 9:40 pm, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
> >> Evil Otto wrote:
> >>> The only error i get is an undefined index message when the third
> >>> request tries to access the $_SESSION variable.
> >>> On Feb 18, 8:37 pm, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
> >>>> Evil Otto wrote:
> >>>>> I removed the ?> and <?php tags from where you saw the whitespace, =
so
> >>>>> there's no extraneous whitespace. Had no effect on the problem I'm
> >>>>> seeing; the third request still cannot see changes to the $_SESSION
> >>>>> variable made by the second.
> >>>>> On Feb 18, 3:24 pm, Kimmo Laine <s... [at] outolempi.net> wrote:
> >>>>>> Evil Otto kirjoitti:
> >>>>>>> There's no output going to the browser before session_start(). T=
he
> >>>>>>> top of my script looks like this:
> >>>>>>> --quote
> >>>>>>> <?php
> >>>>>>> error_reporting(E_ALL);
> >>>>>>> ini_set("display_errors","1");
> >>>>>>> ?>
> >>>>>> Output starts here cos you have a gap between two php tags. It's t=
he
> >>>>>> whitespace effect.
> >>>>>>> <?php
> >>>>>> --
> >>>>>> "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirv=

> >>>>>> s... [at] outolempi.net | Gedoon-S [at] IRCnet | rot13(x... [at] bhgbyrzcv.arg)
> >>>> And can you be sure that *NOTHING* in your include.php file generates
> >>>> output - including leading or trailing blanks, newline characters, e=
tc.?
> >>>> What do you get for error messages?
> >>>> --
> >>>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> >>>> Remove the "x" from my email address
> >>>> Jerry Stuckle
> >>>> JDS Computer Training Corp.
> >>>> jstuck... [at] attglobal.net
> >>>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> >> In that case there are only two options. Either the second page didn't
> >> call session_start() before any output, or the third page didn't do it.
>
> >> Sessions work. If the second page properly starts the session and sets
> >> the session info, and the third page properly starts the session, it
> >> does work.
>
> >> I know this sounds blunt - and I'm really sorry, I don't mean to be
> >> blunt about it. But sessions do work. If you have a case where the
> >> second page sets a session variable and the third page can't read it,
> >> one of two things is wrong:
>
> >> 1. The second page didn't actually set the $_SESSION value in the
> >> session (possibly because session_start wasn't called early enough - b=
ut
> >> there could be other reasons), or
> >> 2. The third page can't read the $_SESSION value. In this case if it
> >> is set, about the only option you have is that session_start() wasn't
> >> called soon enough.
>
> >> So, if the third page (where the value is read) is correct, perhaps the
> >> second page (where it is set) has a problem?
>
> >> It's got to be one or the other.
>
> >> --
> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> >> Remove the "x" from my email address
> >> Jerry Stuckle
> >> JDS Computer Training Corp.
> >> jstuck... [at] attglobal.net
> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>
> Hmmm, when you say
>
> "The content it returns includes a link that calls the same variable,
> but I get an error that says the index isn't defined."
>
> what do you mean exactly? Is this an html link? A function call?
>
> --
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck... [at] attglobal.net
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

This is an onClick attribute in a div that calls a javascript
function, which makes an Ajax request calling a PHP funciton on the
server.

I think i may have cleared this up, however. Turns out a
session_destroy() was in the wrong place, and an undefined index
should have been expected.
zburnham [ Mo, 19 Februar 2007 19:10 ] [ ID #1633950 ]
PHP » alt.php » Can't read $_SESSION variables set by previous request, AJAX

Vorheriges Thema: Need help storing special characters like ° (degrees)
Nächstes Thema: PHP Fusion - request password change