Accessing Session After Ajax Request
Moderator: General Moderators
Accessing Session After Ajax Request
I have session_start() set on the parent page. When I make an ajax request and pull the new page in, I cannot set session_start() again since the headers were already sent. Is there a way to access the session on the child page?
Re: Accessing Session After Ajax Request
AJAX would use the same stateless HTTP protocol, so it makes no difference whether the request is made by user or AJAX ...
Maybe if you post some code we could help you.
Maybe if you post some code we could help you.
There are 10 types of people in this world, those who understand binary and those who don't
Re: Accessing Session After Ajax Request
Maybe I didn't explain myself well. Page1 has a link that when clicked, makes an Ajax call to Page2 and writes Page2 inside a <div> on Page1. So now Page1 has Page2 inside it. The browser never left the web address and never refreshed. Page1 has the session_start() at the top. Page2 cannot read the session since it was not originally parsed with Page1. You would think that the easiest solution would be to put a session_start() at the top of Page2. But you cannot since the headers are already sent.
So, I'm trying to get Page2 to read the session that Page1 initiated. Make sense? There is really no code to post.
So, I'm trying to get Page2 to read the session that Page1 initiated. Make sense? There is really no code to post.
Re: Accessing Session After Ajax Request
Yeah, I know what AJAX is 
So ... why don't you just try to use session_start, $_SESSION, etc. in "Page2" and see what happens
Also make sure there is no ouput before session_start in Page2 (that includes new lines, tabs, spaces etc.)
So ... why don't you just try to use session_start, $_SESSION, etc. in "Page2" and see what happens
Also make sure there is no ouput before session_start in Page2 (that includes new lines, tabs, spaces etc.)
There are 10 types of people in this world, those who understand binary and those who don't
Re: Accessing Session After Ajax Request
Didn't work. A session_start() cannot be set on a page called asynchronously (the headers are already passed and so I get an error on that). Then, I added an echo of a session variable that is echoed on the parent page. On the parent page it works fine, on the child page (called in after parent is parsed and in browser), it doesn't work. Long story short, the session must be initiated on all Ajax requested pages. But it cannot be initiated when the page is requested by another page.
I don't mean to insult your smarts (I'm sure you are smarter than me). I just don't know what else to say. I set up a couple of pages to see what I mean. You can go here to see them: http://www.aliasbdi.com/session.php
I can post the code here as well but the ajax call is super long.
I don't mean to insult your smarts (I'm sure you are smarter than me). I just don't know what else to say. I set up a couple of pages to see what I mean. You can go here to see them: http://www.aliasbdi.com/session.php
I can post the code here as well but the ajax call is super long.
Re: Accessing Session After Ajax Request
output started at /mnt/Target01/331444/331704/www.aliasbdi.com/web/content/page2.php:2
So ... there is some output at line 2 in Page2
There are 10 types of people in this world, those who understand binary and those who don't
Re: Accessing Session After Ajax Request
You are so right!!!! I have a freaking space before it! Ahhhh.. I'm so stupid. Thanks for your patience.