Announcement

Collapse
No announcement yet.

Logout with hash

Collapse
X
Collapse
First Prev Next Last
  • Filter
  • Time
  • Show
Clear All
new posts

    Logout with hash

    I have this for my site: https://www.vbulletin.com/forum/blog...n-your-website

    In the end it says

    PHP Code:
          else     {         echo 'Already logged in';     } 
    I would like to have a link that can logout.

    I have tried this

    PHP Code:

    $hash 
    vB5_Cookie::get('password'vB5_Cookie::TYPE_STRING);
    echo 
    '<a href="https://www.zoopet.com/forum/auth/logout?logouthash=' $hash '" class="btn btn-default">Logout</a>'
    But there is no value to $hash. Is there a good way to get that value.

    #2
    Try this:
    PHP Code:
    $api Api_InterfaceAbstract::instance();
    $user $api->callApi('user''fetchUserinfo', array());
    echo 
    '<a href="https://www.zoopet.com/forum/auth/logout?logouthash=' $user['logouthash'] . '" class="btn btn-default">Logout</a>'

    This code is untested but I think it will work.

    Comment


      #3
      Now the code is tested. It works great. Thank you

      Comment


        #4
        Glad to be of help.

        bill murray pointing GIF

        Comment


          #5
          I got the full code working with login/logout on external pages on Zoopet now. Do you want it and share it?

          Comment


            #6
            Sure you can post it here. Thanks.

            Comment


              #7
              PHP Code:
              <?php

              // Path to your vBulletin installation
              $vbpath '../forum';

              // Start login script
              define('CSRF_PROTECTION'false);
              require_once(
              $vbpath '/includes/vb5/autoloader.php');
              vB5_Autoloader::register($vbpath);
              vB5_Frontend_Application::init('config.php');
              $api      Api_InterfaceAbstract::instance();
              $userInfo $api->callApi('user''fetchProfileInfo', array(
                  
              $userid
              ));

              if (
              $_SERVER['REQUEST_METHOD'] == 'POST') {
                  
              ///////////////////////////////////////////////////////////////////////////////////////
                  // process the login form

                  
              $api       Api_InterfaceAbstract::instance();
                  
              $loginInfo $api->callApi('user''login', array(
                      
              $_POST['username'],
                      
              $_POST['password']
                  ));

                  if (empty(
              $loginInfo['errors'])) {
                      
              // set cookies
                      
              vB5_Auth::setLoginCookies($loginInfo'', !empty($_POST['remember']));

                      
              // redirect somewhere Also see: vB5_Auth::doLoginRedirect();
                      //header('Location: ../index.php');
                      
              header('Location: /index.php');


                      exit;
                  } else {
                      
              // there was a problem logging in.
                      // redirect or display errors here
                  
              }
              } else {
                  
              ///////////////////////////////////////////////////////////////////////////////////////
                  // display a login form

                  
              $userid vB5_Cookie::get('userid'vB5_Cookie::TYPE_UINT);
                  
              $hash   $user['logouthash'];


                  if (
              $userInfo['username'] == '') {
              ?>

              <h1>Logga in p&aring; Zoopet</h1>
              <form action='/forum/login.php' method='post' onsubmit='md5hash(vb_login_password,vb_login_md5pa ssword)'> 
              <script type='text/javascript' src='/forum/clientscript/vbulletin_md5.js'></script> 

              <div class="form-group">

              <input type="text" value="" placeholder="Anv&auml;ndarnamn" class="form-control" name='vb_login_username' onfocus='if (this.value == 'username') this.value = '';'><br>
              <input type="password" name="vb_login_password" value="" placeholder="L&ouml;senord" class="form-control" />
              <div class="checkbox"><label><input type="checkbox" name="cookieuser" checked='checked' /> Stanna inloggad?</label></div>
              <input type="submit" value="Logga in" class="btn btn-default"/> 

              <input type='hidden' name='do' value='login' /> 
              <input type='hidden' name='forceredirect' value='1' /> 
              <input type='hidden' name='vb_login_md5password' />

              </div>
              </form>

              <br>
              <a href="https://www.zoopet.com/forum/register"><span class="glyphicon glyphicon-link" aria-hidden="true"></span>&Auml;r du inte medlem kan du registera dig h&auml;r kostnadsfritt</a><br>
              <a href="https://www.zoopet.com/medlem"><span class="glyphicon glyphicon-link" aria-hidden="true"></span>Vill du bli Goldmedlem och se allt registerar du dig h&auml;r</a><br>



              <?php
                  
              } else {

                      
              $api      Api_InterfaceAbstract::instance();
                      
              $userInfo $api->callApi('user''fetchProfileInfo', array(
                          
              $userid
                      
              ));
                      
              $hash     $userInfo['logouthash'];

                      echo 
              '<h2>Du &auml;r inloggad som: ' $userInfo['username'] . '</h2><br><br>';
              ?>
              <a href="/" class="btn btn-default">Gå vidare till Zoopet</a> eller 
              <?

                      echo '<a href="https://www.zoopet.com/forum/auth/logout?logouthash=' . $hash . '" class="btn btn-default">Logga ut</a>';

                  }
              }


              ?>
              Last edited by glennrocksvb; 04-07-2019, 08:46 PM.

              Comment


              • glennrocksvb
                glennrocksvb commented
                Editing a comment
                Edited code to wrap in [PHP] BBCode tags for readability

              #8
              Thanks for sharing ChristianAlfredsson

              Comment

              Working...
              X