Re: [jQuery] Jquery, AJAX, and php session variables
If that code is not executed in the same request as code that calls session_start(), then you will have problems (though that doesn't appear to be the case). Try adding a call to session_start() just before that code is run, see if that helps at all. Is there any chance that you could send me all of this? It would be a lot easier for me to help you if you could. On 3/30/07, Kim Johnson <[EMAIL PROTECTED]> wrote: Ah, it's actually not... here's the breakdown of the included files: index.php (sample "normal" page which has the login box in it) (included at start of index.php) -page_init.php (included at start of page_init.php) -dbconnect.php //connects database -startsession.php //CALLS SESSION_START() and contains object-like fns for session handling -header.php (included after page_init.php. DOES NOT call session_start as it's already called in page_init.php's included startsession.php page. Contains all of the jquery/ajax which you mentioned below, and all HTML header stuff) --- Aaron Heimlich <[EMAIL PROTECTED]> wrote: > Question: is session_start() called on the page > where this code is run? > > var loggedin = ; > > if (loggedin == true) > { > > $("div#login").hide(); > $("div#logout").unhide(); > } > else > { >$("div#login").unhide(); >$("div#logout").hide(); > } > > On 3/30/07, Kim Johnson <[EMAIL PROTECTED]> wrote: > > > > I am indeed not using output buffering. I call > > session_start as the first thing on every page, > before > > the headers are sent. I also call session_start on > my > > login page, first thing. > > > > If I use output buffering, do you think that would > fix > > things? I could call session_start() again as a > > callback function after the ajax finishes, > perhaps...? > > > > thanks, > > -kim > > > > --- Aaron Heimlich <[EMAIL PROTECTED]> > wrote: > > > > > On 3/30/07, Kim Johnson <[EMAIL PROTECTED]> > wrote: > > > > > > > > Should I be recalling > > > > session_start? > > > > > > > > > As a general rule, you should call > session_start() > > > in *every* PHP script > > > that accesses $_SESSION. Where you call it > depends > > > on whether you're using > > > output buffering or not[1], but it must *always* > be > > > *before* you access > > > $_SESSION for the first time in that script. > > > > > > > > > [1] If you're not using output buffering ( > > > http://us.php.net/manual/en/ref.outcontrol.php), > > > then you *must* call > > > session_start() *before* any output is sent to > the > > > browser, otherwise you'll > > > get a "can't send headers because headers were > > > already sent" error (this > > > means that the call to session_start() should > > > probably be the very first > > > thing your script does). If you are using output > > > buffering, then you can > > > call it pretty much anywhere in your script > before > > > you send the contents of > > > the output buffer to the browser. > > > > > > -- > > > Aaron Heimlich > > > Web Developer > > > [EMAIL PROTECTED] > > > http://aheimlich.freepgs.com > > > > > ___ > > > jQuery mailing list > > > discuss@jquery.com > > > http://jquery.com/discuss/ > > > > > > > > > > > > > > > > > > No need to miss a message. Get email on-the-go > > with Yahoo! Mail for Mobile. Get started. > > http://mobile.yahoo.com/mail > > > > ___ > > jQuery mailing list > > discuss@jquery.com > > http://jquery.com/discuss/ > > > > > > -- > Aaron Heimlich > Web Developer > [EMAIL PROTECTED] > http://aheimlich.freepgs.com > > ___ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ > Food fight? Enjoy some healthy debate in the Yahoo! Answers Food & Drink Q&A. http://answers.yahoo.com/dir/?link=list&sid=396545367 ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/ -- Aaron Heimlich Web Developer [EMAIL PROTECTED] http://aheimlich.freepgs.com ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] Jquery, AJAX, and php session variables
Ah, it's actually not... here's the breakdown of the included files: index.php (sample "normal" page which has the login box in it) (included at start of index.php) -page_init.php (included at start of page_init.php) -dbconnect.php //connects database -startsession.php //CALLS SESSION_START() and contains object-like fns for session handling -header.php (included after page_init.php. DOES NOT call session_start as it's already called in page_init.php's included startsession.php page. Contains all of the jquery/ajax which you mentioned below, and all HTML header stuff) --- Aaron Heimlich <[EMAIL PROTECTED]> wrote: > Question: is session_start() called on the page > where this code is run? > > var loggedin = ; > > if (loggedin == true) > { > > $("div#login").hide(); > $("div#logout").unhide(); > } > else > { >$("div#login").unhide(); >$("div#logout").hide(); > } > > On 3/30/07, Kim Johnson <[EMAIL PROTECTED]> wrote: > > > > I am indeed not using output buffering. I call > > session_start as the first thing on every page, > before > > the headers are sent. I also call session_start on > my > > login page, first thing. > > > > If I use output buffering, do you think that would > fix > > things? I could call session_start() again as a > > callback function after the ajax finishes, > perhaps...? > > > > thanks, > > -kim > > > > --- Aaron Heimlich <[EMAIL PROTECTED]> > wrote: > > > > > On 3/30/07, Kim Johnson <[EMAIL PROTECTED]> > wrote: > > > > > > > > Should I be recalling > > > > session_start? > > > > > > > > > As a general rule, you should call > session_start() > > > in *every* PHP script > > > that accesses $_SESSION. Where you call it > depends > > > on whether you're using > > > output buffering or not[1], but it must *always* > be > > > *before* you access > > > $_SESSION for the first time in that script. > > > > > > > > > [1] If you're not using output buffering ( > > > http://us.php.net/manual/en/ref.outcontrol.php), > > > then you *must* call > > > session_start() *before* any output is sent to > the > > > browser, otherwise you'll > > > get a "can't send headers because headers were > > > already sent" error (this > > > means that the call to session_start() should > > > probably be the very first > > > thing your script does). If you are using output > > > buffering, then you can > > > call it pretty much anywhere in your script > before > > > you send the contents of > > > the output buffer to the browser. > > > > > > -- > > > Aaron Heimlich > > > Web Developer > > > [EMAIL PROTECTED] > > > http://aheimlich.freepgs.com > > > > > ___ > > > jQuery mailing list > > > discuss@jquery.com > > > http://jquery.com/discuss/ > > > > > > > > > > > > > > > > > > No need to miss a message. Get email on-the-go > > with Yahoo! Mail for Mobile. Get started. > > http://mobile.yahoo.com/mail > > > > ___ > > jQuery mailing list > > discuss@jquery.com > > http://jquery.com/discuss/ > > > > > > -- > Aaron Heimlich > Web Developer > [EMAIL PROTECTED] > http://aheimlich.freepgs.com > > ___ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ > Food fight? Enjoy some healthy debate in the Yahoo! Answers Food & Drink Q&A. http://answers.yahoo.com/dir/?link=list&sid=396545367 ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] Jquery, AJAX, and php session variables
On 3/30/07, Kim Johnson <[EMAIL PROTECTED]> wrote: called via ajaxsubmit (async set to false). You should *really* avoid doing this as it completely freezes the entire browser until the request is complete (very bad!!). I highly recommend that you check out Mike Alsup's blockUI plugin ( http://www.malsup.com/jquery/block/) instead. -- Aaron Heimlich Web Developer [EMAIL PROTECTED] http://aheimlich.freepgs.com ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] Jquery, AJAX, and php session variables
Question: is session_start() called on the page where this code is run? var loggedin = ; if (loggedin == true) { $("div#login").hide(); $("div#logout").unhide(); } else { $("div#login").unhide(); $("div#logout").hide(); } On 3/30/07, Kim Johnson <[EMAIL PROTECTED]> wrote: I am indeed not using output buffering. I call session_start as the first thing on every page, before the headers are sent. I also call session_start on my login page, first thing. If I use output buffering, do you think that would fix things? I could call session_start() again as a callback function after the ajax finishes, perhaps...? thanks, -kim --- Aaron Heimlich <[EMAIL PROTECTED]> wrote: > On 3/30/07, Kim Johnson <[EMAIL PROTECTED]> wrote: > > > > Should I be recalling > > session_start? > > > As a general rule, you should call session_start() > in *every* PHP script > that accesses $_SESSION. Where you call it depends > on whether you're using > output buffering or not[1], but it must *always* be > *before* you access > $_SESSION for the first time in that script. > > > [1] If you're not using output buffering ( > http://us.php.net/manual/en/ref.outcontrol.php), > then you *must* call > session_start() *before* any output is sent to the > browser, otherwise you'll > get a "can't send headers because headers were > already sent" error (this > means that the call to session_start() should > probably be the very first > thing your script does). If you are using output > buffering, then you can > call it pretty much anywhere in your script before > you send the contents of > the output buffer to the browser. > > -- > Aaron Heimlich > Web Developer > [EMAIL PROTECTED] > http://aheimlich.freepgs.com > > ___ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ > No need to miss a message. Get email on-the-go with Yahoo! Mail for Mobile. Get started. http://mobile.yahoo.com/mail ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/ -- Aaron Heimlich Web Developer [EMAIL PROTECTED] http://aheimlich.freepgs.com ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] Jquery, AJAX, and php session variables
I am indeed not using output buffering. I call session_start as the first thing on every page, before the headers are sent. I also call session_start on my login page, first thing. If I use output buffering, do you think that would fix things? I could call session_start() again as a callback function after the ajax finishes, perhaps...? thanks, -kim --- Aaron Heimlich <[EMAIL PROTECTED]> wrote: > On 3/30/07, Kim Johnson <[EMAIL PROTECTED]> wrote: > > > > Should I be recalling > > session_start? > > > As a general rule, you should call session_start() > in *every* PHP script > that accesses $_SESSION. Where you call it depends > on whether you're using > output buffering or not[1], but it must *always* be > *before* you access > $_SESSION for the first time in that script. > > > [1] If you're not using output buffering ( > http://us.php.net/manual/en/ref.outcontrol.php), > then you *must* call > session_start() *before* any output is sent to the > browser, otherwise you'll > get a "can't send headers because headers were > already sent" error (this > means that the call to session_start() should > probably be the very first > thing your script does). If you are using output > buffering, then you can > call it pretty much anywhere in your script before > you send the contents of > the output buffer to the browser. > > -- > Aaron Heimlich > Web Developer > [EMAIL PROTECTED] > http://aheimlich.freepgs.com > > ___ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ > No need to miss a message. Get email on-the-go with Yahoo! Mail for Mobile. Get started. http://mobile.yahoo.com/mail ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] Jquery, AJAX, and php session variables
As a side note, if you (or anyone else, for that matter) are having problems with Tredosoft's MultipleIEs (http://tredosoft.com/Multiple_IE) and PHP sessions, be sure to upgrade to at least the version that was released on 07/11/2006 (November 11, 2006) as versions before that had issues with cookies and sessions. On 3/30/07, Aaron Heimlich <[EMAIL PROTECTED]> wrote: On 3/30/07, Kim Johnson <[EMAIL PROTECTED]> wrote: > > Should I be recalling > session_start? As a general rule, you should call session_start() in *every* PHP script that accesses $_SESSION. Where you call it depends on whether you're using output buffering or not[1], but it must *always* be *before* you access $_SESSION for the first time in that script. [1] If you're not using output buffering ( http://us.php.net/manual/en/ref.outcontrol.php), then you *must* call session_start() *before* any output is sent to the browser, otherwise you'll get a "can't send headers because headers were already sent" error (this means that the call to session_start() should probably be the very first thing your script does). If you are using output buffering, then you can call it pretty much anywhere in your script before you send the contents of the output buffer to the browser. -- Aaron Heimlich Web Developer [EMAIL PROTECTED] http://aheimlich.freepgs.com -- Aaron Heimlich Web Developer [EMAIL PROTECTED] http://aheimlich.freepgs.com ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] Jquery, AJAX, and php session variables
On 3/30/07, Kim Johnson <[EMAIL PROTECTED]> wrote: Should I be recalling session_start? As a general rule, you should call session_start() in *every* PHP script that accesses $_SESSION. Where you call it depends on whether you're using output buffering or not[1], but it must *always* be *before* you access $_SESSION for the first time in that script. [1] If you're not using output buffering ( http://us.php.net/manual/en/ref.outcontrol.php), then you *must* call session_start() *before* any output is sent to the browser, otherwise you'll get a "can't send headers because headers were already sent" error (this means that the call to session_start() should probably be the very first thing your script does). If you are using output buffering, then you can call it pretty much anywhere in your script before you send the contents of the output buffer to the browser. -- Aaron Heimlich Web Developer [EMAIL PROTECTED] http://aheimlich.freepgs.com ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] Jquery, AJAX, and php session variables
Thanks to both of you for your responses, I guess I'm still having a hard time wrapping my head around what AJAX is doing with my session vars that make it impossible to use in my existing PHP files. I was under the impression that session vars are just ... around in the browser, so if they are set on an ajax called page, that I'd be able to use them in the page I called it from. Even if I passed the session ID back in the requestText, let's say... based on the behavior I saw it's not seeing any of the variables I set in the ajax file, so it doesn't matter if I have one of 5 variables but not the rest. Users won't always set variables in a cookie, as that's just if they want to be remembered. I could switch to ajaxform, I just don't understand why that would work for accessing the sessions instead of what I'm doing. Should I be recalling session_start? Or just reloading the whole page and not bothering with ajax? etc... thanks, -kim --- Jake McGraw <[EMAIL PROTECTED]> wrote: > I believe you aren't handling the session correctly, > remember, AJAX > calls don't automatically attach the session ID to > your URL variables, > so you have to do it manually (if it's not in the > cookie), either by > directly attaching to the target url: > > $.getJSON("target.php?sid="+,...,...); > > or within you arguments (my preferred method): > > $.getJSON("target.php",{sid:,...},...); > > Then on the server side: > > // Check if our session is still active > if (session_id() == "") { > // Not active, check if sid was sent > if (!$_REQUEST['sid']) { > // Not sent, bounce them out (or attempt to > log them in) > } else { > session_id($_REQUEST['sid']); > session_start(); > } > } > > Note, that this is the bare bones way of doing it > and I can't vouch > for the security. You're probably best off creating > a class for > handling sessions. > > - jake > On 3/30/07, Erik > Beeson <[EMAIL PROTECTED]> wrote: > > I don't know much about your specific problem, but > I thought I'd share > > how I do AJAXified login. First I have a form with > action set to the > > login page so it will work without javascript. > Then I hijack the form > > with ajaxForm() from the form plugin. I have the > ajax return JSON and > > have a callback function like: > > > > function(data) { > > if(data.loggedIn) { > > // Do logged in stuff > > } else { > > $('#login_error').html(data.errorMessage); > > } > > } > > > > Also, I use asynchronis ajax and disable the > fields and display an > > indicator in the form plugin's beforeSubmit() > function. The blockUI > > plugin is good for doing this kind of thing. > > > > Hope it helps. > > > > --Erik > > > > On 3/30/07, Kim Johnson <[EMAIL PROTECTED]> > wrote: > > > Hi folks, > > > > > > I apologize if this is a little less Jquery and > a > > > little more "general AJAX/PHP" in nature, but I > am > > > completely stuck and was hoping there's tribal > > > knowledge I failed to learn. > > > > > > I have a login panel on each page of my site. > The > > > actual authentication takes place in a file > called > > > login.php, called via ajaxsubmit (async set to > false). > > > login.php calls a few functions that are in an > > > included file called startsession.php (meaning, > > > startsession.php is included in every normal > page; > > > it's not called/included using ajax or > anything). > > > These startsession functions handle setting > $_SESSION > > > vars once the user is authenticated (or removes > them > > > if the user is logged out or information is > corrupt, > > > etc). > > > > > > Both the regular page and login.php call > > > session_start(). > > > > > > I'm seeing some very weird behavior. > > > > > > startsession appears to be setting the $_SESSION > vars > > > correctly. The problem is, they don't seem to > be > > > sticking. First of all, startsession.php appears > to > > > refresh itself AFTER the ajax call is complete, > even > > > though the only places this file would be in are > in > > > login.php (already called in ajaxsubmit) and the > > > regular file. When startsession.php refreshes > itself, > > > it doesn't see the $_SESSION vars and > subsequently > > > logs me out. > > > > > > Furthermore, I was under the impression that I > could > > > do something like this, after the ajax call: > > > > > > var loggedin = ; > > > > > > if (loggedin == true) > > > { > > > > $("div#login").hide(); > $("div#logout").unhide(); > > > } > > > else > > > { > > > $("div#login").unhide(); > > > $("div#logout").hide(); > > > } > > > > > > I had been hoping to avoid reading the > responseText... > > > though after looking at it now, I'm realizing > that > > > there's no way this would work; even though > session > > > vars are set on, well, the session, it seems > that > > > you'd have to reload the page for PHP to pick it > up, > > > period. > > > > > > Any help would be greatly appr
Re: [jQuery] Jquery, AJAX, and php session variables
I believe you aren't handling the session correctly, remember, AJAX calls don't automatically attach the session ID to your URL variables, so you have to do it manually (if it's not in the cookie), either by directly attaching to the target url: $.getJSON("target.php?sid="+,...,...); or within you arguments (my preferred method): $.getJSON("target.php",{sid:,...},...); Then on the server side: // Check if our session is still active if (session_id() == "") { // Not active, check if sid was sent if (!$_REQUEST['sid']) { // Not sent, bounce them out (or attempt to log them in) } else { session_id($_REQUEST['sid']); session_start(); } } Note, that this is the bare bones way of doing it and I can't vouch for the security. You're probably best off creating a class for handling sessions. - jake On 3/30/07, Erik Beeson <[EMAIL PROTECTED]> wrote: > I don't know much about your specific problem, but I thought I'd share > how I do AJAXified login. First I have a form with action set to the > login page so it will work without javascript. Then I hijack the form > with ajaxForm() from the form plugin. I have the ajax return JSON and > have a callback function like: > > function(data) { > if(data.loggedIn) { > // Do logged in stuff > } else { > $('#login_error').html(data.errorMessage); > } > } > > Also, I use asynchronis ajax and disable the fields and display an > indicator in the form plugin's beforeSubmit() function. The blockUI > plugin is good for doing this kind of thing. > > Hope it helps. > > --Erik > > On 3/30/07, Kim Johnson <[EMAIL PROTECTED]> wrote: > > Hi folks, > > > > I apologize if this is a little less Jquery and a > > little more "general AJAX/PHP" in nature, but I am > > completely stuck and was hoping there's tribal > > knowledge I failed to learn. > > > > I have a login panel on each page of my site. The > > actual authentication takes place in a file called > > login.php, called via ajaxsubmit (async set to false). > > login.php calls a few functions that are in an > > included file called startsession.php (meaning, > > startsession.php is included in every normal page; > > it's not called/included using ajax or anything). > > These startsession functions handle setting $_SESSION > > vars once the user is authenticated (or removes them > > if the user is logged out or information is corrupt, > > etc). > > > > Both the regular page and login.php call > > session_start(). > > > > I'm seeing some very weird behavior. > > > > startsession appears to be setting the $_SESSION vars > > correctly. The problem is, they don't seem to be > > sticking. First of all, startsession.php appears to > > refresh itself AFTER the ajax call is complete, even > > though the only places this file would be in are in > > login.php (already called in ajaxsubmit) and the > > regular file. When startsession.php refreshes itself, > > it doesn't see the $_SESSION vars and subsequently > > logs me out. > > > > Furthermore, I was under the impression that I could > > do something like this, after the ajax call: > > > > var loggedin = ; > > > > if (loggedin == true) > > { > > $("div#login").hide(); > > $("div#logout").unhide(); > > } > > else > > { > > $("div#login").unhide(); > > $("div#logout").hide(); > > } > > > > I had been hoping to avoid reading the responseText... > > though after looking at it now, I'm realizing that > > there's no way this would work; even though session > > vars are set on, well, the session, it seems that > > you'd have to reload the page for PHP to pick it up, > > period. > > > > Any help would be greatly appreciated. I know this is > > probably something easy. :/ > > > > thanks, > > -kim > > > > > > > > > > No need to miss a message. Get email on-the-go > > with Yahoo! Mail for Mobile. Get started. > > http://mobile.yahoo.com/mail > > > > ___ > > jQuery mailing list > > discuss@jquery.com > > http://jquery.com/discuss/ > > > > ___ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ > ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] Jquery, AJAX, and php session variables
I don't know much about your specific problem, but I thought I'd share how I do AJAXified login. First I have a form with action set to the login page so it will work without javascript. Then I hijack the form with ajaxForm() from the form plugin. I have the ajax return JSON and have a callback function like: function(data) { if(data.loggedIn) { // Do logged in stuff } else { $('#login_error').html(data.errorMessage); } } Also, I use asynchronis ajax and disable the fields and display an indicator in the form plugin's beforeSubmit() function. The blockUI plugin is good for doing this kind of thing. Hope it helps. --Erik On 3/30/07, Kim Johnson <[EMAIL PROTECTED]> wrote: > Hi folks, > > I apologize if this is a little less Jquery and a > little more "general AJAX/PHP" in nature, but I am > completely stuck and was hoping there's tribal > knowledge I failed to learn. > > I have a login panel on each page of my site. The > actual authentication takes place in a file called > login.php, called via ajaxsubmit (async set to false). > login.php calls a few functions that are in an > included file called startsession.php (meaning, > startsession.php is included in every normal page; > it's not called/included using ajax or anything). > These startsession functions handle setting $_SESSION > vars once the user is authenticated (or removes them > if the user is logged out or information is corrupt, > etc). > > Both the regular page and login.php call > session_start(). > > I'm seeing some very weird behavior. > > startsession appears to be setting the $_SESSION vars > correctly. The problem is, they don't seem to be > sticking. First of all, startsession.php appears to > refresh itself AFTER the ajax call is complete, even > though the only places this file would be in are in > login.php (already called in ajaxsubmit) and the > regular file. When startsession.php refreshes itself, > it doesn't see the $_SESSION vars and subsequently > logs me out. > > Furthermore, I was under the impression that I could > do something like this, after the ajax call: > > var loggedin = ; > > if (loggedin == true) > { > $("div#login").hide(); > $("div#logout").unhide(); > } > else > { > $("div#login").unhide(); > $("div#logout").hide(); > } > > I had been hoping to avoid reading the responseText... > though after looking at it now, I'm realizing that > there's no way this would work; even though session > vars are set on, well, the session, it seems that > you'd have to reload the page for PHP to pick it up, > period. > > Any help would be greatly appreciated. I know this is > probably something easy. :/ > > thanks, > -kim > > > > > No need to miss a message. Get email on-the-go > with Yahoo! Mail for Mobile. Get started. > http://mobile.yahoo.com/mail > > ___ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ > ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/