473,567 Members | 2,902 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.

Feb 18 '07 #1
15 5931
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("displa y_errors","1");
?>

No whitespace or anything else before it.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Feb 18 '07 #2
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
Feb 18 '07 #3
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.
Feb 18 '07 #4
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
Feb 18 '07 #5
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("displa y_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('i ncludes.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...@attg lobal.netwrote:
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("displa y_errors","1");
?>

No whitespace or anything else before it.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attgl obal.net
=============== ===

Feb 18 '07 #6
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("displa y_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ö
sp**@outolempi. net | Gedoon-S @ IRCnet | rot13(xv***@bhg byrzcv.arg)
Feb 18 '07 #7
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...@outolempi .netwrote:
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("displa y_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...@outolempi. net | Gedoon-S @ IRCnet | rot13(x...@bhgb yrzcv.arg)

Feb 18 '07 #8
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...@outolempi .netwrote:
>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("displa y_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...@outolempi .net | Gedoon-S @ IRCnet | rot13(x...@bhgb yrzcv.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.
js*******@attgl obal.net
=============== ===
Feb 19 '07 #9
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.
js*******@attgl obal.net
=============== ===
Feb 19 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1271
by: Ken | last post by:
How do I save the values (not variables) for the variables in a file? Example: $_SESSION = "TEST"; $url_read = readfile.php; $url_write = writefile.php; $sort = "var ".$_SESSION; // read file
8
3523
by: chris_fieldhouse | last post by:
Hi fairly new to php, but picking it up quite well. the question I have, is it possible for a php script which is used to validate values submitted in a form, to then post these values onto another script/page or even back to the calling form? i.e. the application I have in question is a login.htm page with a verify.php script The...
9
2801
by: cendrizzi | last post by:
Hi all, I've read some stuff on this but can't seem to come up with a solution that works right. I have a semi-mature (yet very large and robust) internal web application that currently only works with one window open at a time. Maybe I'm abusing the use of $_SESSION but I have data entry processes split up in several steps (which is...
7
2024
by: mantrid | last post by:
I have some code to upload files to my site. it works when the <input type="file" is posted once even when I use session variables from the posted variables but when I carry those session variables to a new page the upload will not work. despite the variables being set. I have echoed then on the second page and they display correctly but they...
1
1503
by: moho | last post by:
Hi I'm trying to use $_SESSION in my AJAX application. However this gives me strange data, the $_SESSION variable seems to change during page load. in the end of the page it's the earlier value that shows. I set the $_SESSION with this function setId(id) { try{ var obj;
13
3972
by: Marvin Zhang | last post by:
Hi, I'm not familiar with web programming, but I have a problem here. I have a page. When a user click one button on it, I will use AJAX to request a PHP script which will do a bunch of tasks, asynchronously. These tasks might take long time so I want to keep the user informed of the progress. The problem is that only the PHP script knows...
6
5128
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick application working. However, when attempting to implement the solution, the AJAX calls weren't updating the screen like the examples were and...
4
1803
TheServant
by: TheServant | last post by:
Hi guys, This is my situation. I have 3 sets of data used on every page of my website. Two of these never change, and the reason they are stored in MySQL and recalled into the $_SESSION variable is simply because I want to have one place to update/change them if I ever need to. What I have been wondering is if I should leave the user specific...
5
4442
by: thatcollegeguy | last post by:
Below are my 3php and 2js files. I create a table using ajax/php and then want to change the values in the tables add(+ number for teamid) id's for each specific td in the table. I don't know if I have the entirely wrong approach, but my code is below. Any or all help is appreciated! What currently happens is that the getdivision.php...
0
7688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7905
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7651
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7960
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6272
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5488
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5216
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3630
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.