A
A
Alexey Yarkov2014-12-22 19:52:16
PHP
Alexey Yarkov, 2014-12-22 19:52:16

AJAX session check. How to do?

There is a website and an admin panel. The admin panel is completely AJAX. If you enter the admin panel, and log out on the site, then the session remains in the admin panel. There is a script in the admin/ajax.php directory that handles requests from the admin area. It is necessary to terminate the session in the admin panel when exiting through the site. At the beginning of ajax.php I inserted the following code:

session_start();
require_once("../auth.php");
$auth = new AuthClass();
$access = $auth->isAdmin(); // проверка на авторизованного админа
if(!$access){
  header("HTTP/1.1 301 Moved Permanently");
  header("Location: ../index.php");
  exit();

In theory, it should transfer to the main page of the site, if you send a request from the admin panel and at the same time log out through the site. But there is no redirect! Requests are no longer processed, lines of redirect attempt and loading of the Vkontakte widget appear in the status bar (comments on the main page). But it doesn't redirect. Stupidly the page hangs and that's it.
Of course, I can read the active field from the database with each request, and if it is 0, then do something (close the admin page with a modal window, etc.). But I want to tie everything to the authorization class without perversions.
Let me know if anyone has come across.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel K, 2014-12-22
@yarkov

You just get an AJAX request redirect to the index.php address
. In this case, you just need to return the need to go to the desired address as a response, and on the client side in JS, process the response and go.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question