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
558 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 109

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 109

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What does GoogleTagMgr javascripts below do 5 35
Log in through ID 5 18
Character counter breaks after adding EmojiOne Area 4 23
JQuery Search Filter 2 35
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
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?
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

827 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