• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 567
  • Last Modified:

If i clear the php sessions in a jQuery AJAX website how to redirect to login page on any link click

Hey guys,

Does anyone know how to redirect a jQuery AJAX website when the cache is cleared (PHP Sessions cleared) to a login page after any link is clicked.

Gmail does it when you clear the cache/sessions. I'm not sure how replicate in PHP/Javascript/JQuery.

Thanks in advance!
0
dev09
Asked:
dev09
  • 2
3 Solutions
 
Ray PaseurCommented:
Sessions consist of two objects of interest.  A cookie on your browser holds a key.  On the server, the key is used to look up information about the "state" or your interactivity with the web site.  Each time the browser is started it sends the cookie to the server.  

So let's say that you have a logged in status held in the server, and associated with your browser session via the cookie.  There are two ways you can get logged out.  One is to lose the cookie, and the other is to change the information on the server so that your credentials no longer show you to be logged in.

AJAX does not really matter very much in this design pattern.  It can appear to be doing things without reloading the browser, but the background calls to the server are still the important moving part.  Once a signal is given to clear the cache, the background script will respond with instructions to load the login page (instead of whatever the script would be loading otherwise).
0
 
LFLFMCommented:
You should check the session every time ANY requests come to your server; if any check fails: BAM, redirect the user to the login page instead of replying what they asked for...
So, if the user clears the cookies on his browser, the next request to your server (your PHP codes) will fail the session check and your reply will get them back to the login page.

I can't give you any exact code since it really depends on the logic you are using on your PHP's and AJAX; but I can give you these pointers:
- If your AJAX makes a request to your PHP for a simple answer, add a check (to your ajax) that the answer was given by the php, if the answer was not given, your PHP failed the session check, so the AJAX must transfer your user into the login page
- if your links go to another section of the site, so the whole page will refresh with the new content suplied by your PHP, simply making the PHP session check reply the login page when it fails will sove your problem
0
 
Ray PaseurCommented:
This article shows the design pattern for password-protecting your pages with simple PHP authentication.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_2391-PHP-login-logout-and-easy-access-control.html
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now