473,657 Members | 2,436 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 5944
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
1276
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
3526
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 login.htm has a Form which captures login_id and password which are posted to verify.php
9
2807
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 required since depending on what was put before determines what pages will be shown after). To store...
7
2033
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 just dont work in the move_uploaded_file() function. I get the error message Error uploading...
1
1508
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
3990
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 the progress, how can the web page gets these information from PHP script?
6
5141
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 seemed not to fire until after the long running process had completed. I found the only real...
4
1807
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 variables in the session, and define the other variables in another file/array which is called on...
5
4456
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 script works perfectly and gives me an entire table of correct data. The problem is that when I click...
0
8310
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8826
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7330
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6166
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
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
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.