Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/299487-sessions-and-jquery-ajax/
Share on other sites

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.

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.

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?

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.