I'm developing a Wordpress web site and I've to handle sessions using $_SESSION in php.
I've start the session in function.php in my theme using the following code.
if (!session_id()) {
session_start();
}
Then the login procedure works fine with all $_SESSION variables in place. I use the following code to log out a user.
if(isset($_POST['logout-submit'])){
session_destroy();
$page_id = get_page_by_title('My Login');
wp_redirect( get_permalink($page_id->ID ));
exit;
}
The logout procedure works fine and redirects to the login page. I've added the following code to pages so that users cannot manually access a page without logging in.
if(!isset($_SESSION['user'])){
$page_id = get_page_by_title('My Login');
wp_redirect( get_permalink($page_id->ID ));
exit;
}
The problem is when I try to go to that page manually, the page loads for a few seconds and the browser shows as following.
This webpage has a redirect loop
What am I doing wrong here?
Aucun commentaire:
Enregistrer un commentaire