Send a title to redirect the entire window?

So, in my php authentication library, if someone is not logged in, they are redirected to the home page:

redirect('home/index');

The problem is that I have modal windows that load content through ajax. If the user somehow logged out (but still on the page where they "logged in"), the modal shows the login page, since the modal was "redirected" to the home page.

This problem may occur if the user has not done anything for a long time (and logged out), or if they have several tabs open and exit on one of them, and on the other hand try to open a modal pop-up window.

Is there a way to redirect the whole window?

+3
source share
7 answers

two solutions:

1) install javascript functions on the main page every x seconds to check the cookie, if it does not exist, redirect the whole page

location.href="login.php"

2) on the page loaded by ajax, set the javascript code to redirect, you cannot do this with PHP, since the script cannot know the context, it is just a preliminary processing of the request result. Javascript code that can be printed using PHP anywhere (including the case)

  if (notLogged){
      window.redirect='login.php';
    }
+1
source

, HTML , , , . , . , "login_form", ajax :

function(data){
    if($(data).find("#login_form").length>0)
        location.href="/login_url"
    else{
        //handle the ajax response
    }
}
0

Ajax-, "". , - window.location.href="myserver.com/home/"; Ajax-.

0

, , - : , ajax, , " " javascript ajax return location.href .

0

, - xmlhttprequest... $_SERVER['HTTP_X_REQUESTED_WITH']. , "XMLHttpRequest", . , , , , , , .

, , script ... .

0

Use a session before opening a modal. Each time you click or send, there should be a session check, and it will be redirected.

0
source

You can always redirect the entire window using the title function, redirecting the user to any desired page.

<?php header('Location: myserver.com/home/'); ?>
-1
source

Source: https://habr.com/ru/post/1766750/


All Articles