doni49 Posted November 15, 2015 Share Posted November 15, 2015 I'm working to develop a web app using jQuery and AJAX on the client side and PHP on the server side. The app processes the login as an AJAX call (using jQuery code). If after logging in the user refreshes the page, they're presented with the login page again. Prior to using AJAX, I would set a SESSION variable upon login. And upon refresh, the PHP script would see that the SESSION variable is set and not display the login page again. How can I make the calling page recognize SESSION variables set by php scripts called via AJAX? Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted November 15, 2015 Share Posted November 15, 2015 you would use the same method, to not output the login form, when the visitor is already logged in, regardless of using any ajax. in fact, your page should work even if javascript is disabled. javascript/ajax only changes how client-side things occur. aside from adding logic to check if the request is an ajax request and to output only what the ajax expects, rather than the entire html document, you need the same functionality in the server-side code, ajax or not. Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 15, 2015 Author Share Posted November 15, 2015 That's what I thought. My index.php file first checks to see if specific SESSION vars are set. If they aren't, then the first thing the page does is show the login page. The login page makes an AJAX call to a php file which if the login info matches the DB, sets the aforementioned SESSION vars and then returns json code telling AJAX to show the next page. The "next page" loads fine. But if I press F5, I'm presented with the login page again. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted November 15, 2015 Share Posted November 15, 2015 are you getting any session_start() errors? is the host-name(sub-domain) and the path after the domain the same for the ajax requested file and the main file and your session cookie settings are only set up to match the exact host-name/path where the session is created, meaning that you have multiple different sessions? Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 15, 2015 Author Share Posted November 15, 2015 No errors and same path/host. I thought it was somehow related to the php script (in the AJAX calls) being a separate call from the original file. I'll investigate further when I get home. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.