PHP When session times out it redirects entire page instead of page loaded via ajax
I have a php page that uses php sessions as well as jquery to call pages via ajax. The problem is if the page is idle for so long the page being called via ajax gets redirected to the home page but the rest of the page outside the div being updated with the ajax still shows the person logged in until they try to click a link then the whole page redirects to the login page since the session has timed out. Is there a way in php that once it detects the session has timed out then redirects them to the logout page that the whole page gets redirected instead of just the page bei开发者_StackOverflow中文版ng called via ajax? Perhaps a solution via jquery could work? Hope this makes sense.
you can detect the session is timed out or not in php. If it is timed out, just return,
echo "<script>window.top.location.href='$url'</script>";
where $url is your redirection url.
Here I've derrived a method in my project and it is very successful. You can check it out in this link
https://stackoverflow.com/a/32109862/3141187
精彩评论