dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Ajax and sessions?

  1. #1
    Join Date
    Dec 2007
    Posts
    2

    Red face Ajax and sessions?

    Hi, has anyone had any issues using sessions in Ajax? I have taken over a project using php and prototype, and when I tried to switch the user authentication over to sessions (as opposed to putting everything in a get request, including the password!), the ajax-fetched pages don't see the session. Has anyone else seen this?

    I have the first page, index.php. It creates the session.
    <?php
    session_start();
    $sis = session_id();
    echo("Session ID is: $sis.");
    //etc
    ?>

    The session id gets displayed fine here.

    Then in the javascript for the index.php page, as soon as the page is loaded, it goes to fetch a section of the page. This is the Ajax code:

    function ajax_getdata(text_id, url, inputlist) {
    var myAjax = new Ajax.Updater(
    text_id,
    url,
    {
    method: 'get',
    parameters: inputlist,
    evalscripts:true
    });
    }

    The php file the url refers to does it's thing, and returns the data requested as html. Put when I try to access the session data, or even print out the session ID, I get nothing!
    for example, if I put this in the php file:
    echo 'Session ID is: ' . session_id();

    nothing shows up for the session id.

    I am new to php programming (I usually program in Java), so maybe I am doing something wrong with the session? I have searched all over the internet for "ajax session" and it seems no one else has this problem, and php sessions seem straight-forward, but still it doesn't work. I'm about to go nuts as I have a deadline coming up. Can anyone please help?

    Thanks,

    Pam

  2. #2
    Join Date
    Dec 2007
    Posts
    2

    I figured it out...

    Okay, nevermind, I just figured it out. Apparently in php you have to call session_start() on every single page you want to use sessions in. Now it works!

    Thanks anyways.... always good to see a forum for help like this!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center