You are here: Re: Can't read $_SESSION variables set by previous request, AJAX « All PHP « IT news, forums, messages
Re: Can't read $_SESSION variables set by previous request, AJAX

Posted by Evil Otto on 02/18/07 20:09

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...@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...@attglobal.net
> ==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация