Jump to content

Recommended Posts

Posted

Hello,

I added this code:

<?php

if($user->isLoggedin()) {
  // if user logged in, show Logout-link!
  echo "<a href='login/login/logout'>Logout</a>";
};

If the user logout, then redirect to the same page.

How can I do that?

Grtz,

Christophe

Posted

here we go:

https://processwire.com/talk/topic/107-custom-login/#entry735

<?php //color your code!

if($user->isLoggedin()) {
    // user is already logged in, so they don't need to be here
    $session->redirect("/somewhere/"); 
}

// check for login before outputting markup
if($input->post->user && $input->post->pass) {

    $user = $sanitizer->username($input->post->user);
    $pass = $input->post->pass; 

    if($session->login($user, $pass)) {
        // login successful
        $session->redirect("/somewhere/"); 
    }
}
Posted

It's easy :)

Add to any page

if ($user->isLoggedin()){
//get link with current page id
echo "<a href='/logout" . "?redirect=$page->id" . "'>Logout</a>";
}

To logout.php

<?php 
//get page id from input
$redirect = $sanitizer->name(wire('input')->get->redirect);
//get url from page id
$url = $pages->get($redirect)->url;

if($user->isLoggedin()) $session->logout();
$session->redirect($url);
?>
  • Like 2
Posted

Hi guys,

Thanks for the fast answers. I like it  ;)

Alexander,

I added your code and added a logout.php, but  after redirect, it shows a 404 page.

Thats the link after click on logout:

http://mysite.com/logout?redirect=1

I'm a newbie and not so easy for me this code. I've got the basics, but thats it  :-[

But I learned  ^_^

Christophe

Posted

@tuxy

Make sure that you put right URL to your logout page in "<a href='/logout'>".

I recommend you to use ProcessWire API to get right URL.

<?php echo "<a href='" . $pages->get("id=33977")->url  . "?redirect=$page->id". "'>Logout</a>"; ?>

33977 change to your logout ID page. If you don't know how to find page ID just try to edit that page and get it from url /page/edit/?id=33977

?redirect=1 probably mean that you try to to logout from homepage, which always have ID=1.

  • Like 2
Posted

Aaaaaah, OK  Alexander 

I added only a logout.php file with your code, but NOT a template in the backend  ???

Thanks for the useful tip, how finding the page-id  ;)

Christophe

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...