Announcement

Collapse
No announcement yet.

Access denied when not logged in? How to check

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

    Access denied when not logged in? How to check

    This code connects to vBulletin 6 from non-vb page

    This code is first

    PHP Code:
    $vbpath 'forum';
    require_once(
    $vbpath '/includes/vb5/autoloader.php');
    vB5_Autoloader::register($vbpath);
    require_once(
    $vbpath '/includes/vb5/config.php');​ 
    that workes fine if user is logged in or not. This line gets access denied if user is not logged in.

    PHP Code:
    $api Api_InterfaceAbstract::instance(); 
    ​is there a way to check if user is logged in or not? Then I can do an if around and ask them to login.

    #2
    Check this blog post from a vB dev. The way you init the config is different than their code. It also has the same API instantiation code that is done during login which indicates it works even if user is logged out.

    When designing your website and integrating vBulletin with the rest of your site, it's often desirable to have a centralized login form for users to initiate a vBulletin session. Here are some instructions
    Helpful? Donate. Thanks!
    Buy me a coffeePayPal QR Code
    Fast VPS Host for vBulletin:
    A2 Hosting & IONOS

    Comment


      #3
      Here is two ways to get userid. The code you linked to had the cookie way. I would like to use api and check

      Code:
      //API way
          $api = Api_InterfaceAbstract::instance();
          $userInfo = $api->callApi('user', 'fetchProfileInfo', array($userid));
          $userid = $userInfo['userid'];
          echo "Userid: " . $userid;
      
      //Cookie way
          $userid = vB5_Cookie::get('userid', vB5_Cookie::TYPE_UINT);
          $hash = vB5_Cookie::get('password', vB5_Cookie::TYPE_STRING);
      
          echo "Userid: " . $userid;​

      Comment


        #4
        Did you try changing the way you init/load the config.php to how it's done in the blog post? Maybe you just need to init the config properly. I don't see any reason why the code Api_InterfaceAbstract::instance() would fail for guest users. In the forum itself, that line of code is being executed everywhere for all users, logged in or not, without any issues.
        Helpful? Donate. Thanks!
        Buy me a coffeePayPal QR Code
        Fast VPS Host for vBulletin:
        A2 Hosting & IONOS

        Comment

        Users Viewing This Page

        Collapse

        There is 1 user viewing this forum topic.

        • Guest Guest

        Latest Posts

        Collapse

        Working...
        X
        Searching...Please wait.
        An unexpected error was returned: 'Your submission could not be processed because you have logged in since the previous page was loaded.

        Please push the back button and reload the previous window.'
        An unexpected error was returned: 'Your submission could not be processed because the token has expired.

        Please push the back button and reload the previous window.'
        An internal error has occurred and the module cannot be displayed.
        There are no results that meet this criteria.
        Search Result for "|||"