Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
Medium Priority
?
565 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 111

Accepted Solution

by:
Ray Paseur earned 1332 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 668 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 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1332 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

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

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

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

618 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