After logout again if user clicks on the browser back button then the previous page showing again instead of login page. I am using a wordpress method called "wp_logout_url() " as a logout url. can anyone out there please help me in this. Thanks in advance.
Asked
Active
Viewed 1,605 times
-2
-
Did you read the details of [wp_logout_url()](https://codex.wordpress.org/Function_Reference/wp_logout_url#Default_Usage)? There are explanations with the redirections included there. Also if you want to interact with browsers back button, the only way to do it is using JavaScript as Tiger showed you... – dingo_d Nov 23 '16 at 16:47
-
@dingo_d, I have already read about the wp_logout_url() redirections but they were not working. Also tried other solutions like '' but no luck. – Prasad Patel Nov 24 '16 at 05:18
1 Answers
3
You need to use session variable for login and logout. More Details on PHP Session
Use below code to check for session variable
<?php
if(!isset($_SESSION['login'])) :
header("Location: login.php");
?>
When user logout, simply unset the login session variable, and destroy the session as below.
<?php
unset($_SESSION['login']);
session_destroy();
?>
Also if you want to disable the back button using javascript. I found here something useful for you.
history.pushState(null, null, document.URL);
window.addEventListener('popstate', function () {
history.pushState(null, null, document.URL);
});
-
no bro our entire application built on wordpress. here we were not using php if we did then I know the solution. As I told we were using a wordpress method called "wp_logout_url() " as a logout URL. – Prasad Patel Nov 23 '16 at 14:21
-
worked like a charm. But it is totally disabling the browser back button. My question is that what if user wants to use browser back button to navigate through the web pages after user login? – Prasad Patel Nov 24 '16 at 05:51