Jump to content

PHP $_Session w/ AJAX


jcanker

Recommended Posts

After much pre-planning, I'm getting ready to start my first foray into AJAX, but I have one question first that will affect my planned scripts:

 

I prefer to have all of my html outputted via  php rather than sneak php variables into the html.  In other words, as the php script unfolds, it builds $output as it goes, and the last step of the script is to echo $output. 

 

I plan to keep doing this with the pages utilizing html and javascript when I turn to AJAX, but if the php script called forth via AJAX has a session_start(), will it use the same session already in use, or will I essentially be confusing the system and starting 2 separate sessions?

 

I hope my intent was clear.  Basically, a php page runs security scripts and such before building the html containing the javascript.  When AJAX sends an async call to another php page which also runs some security scripts and such, can that called php page use the same session variables or will it be starting a separate session and getting confuzzled?

Link to comment
Share on other sites

As far as the web server is concerned, the http requests that AJAX makes are identical to the http requests due to clicking on a link or typing a URL into your browser's address bar. Your browser will send any cookie/session id cookie that is valid, has not expired, and matches the URL/page being requested with any http request that is made via AJAX or any other method.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.