Solved

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

Posted on 2011-02-24
3
552 Views
Last Modified: 2012-05-11
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
Comment
Question by:dev09
  • 2
3 Comments
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 333 total points
ID: 34970062
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
 
LVL 3

Assisted Solution

by:LFLFM
LFLFM earned 167 total points
ID: 34970265
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
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 333 total points
ID: 34971108
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses four methods for overlaying images in a container on a web page
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to dynamically set the form action using jQuery.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now