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
560 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 110

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 110

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

705 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