$vbulletin->userinfo['userid'] always empty inside the forum, how can i use it?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kopfnick
    New Member
    • Dec 2005
    • 7

    $vbulletin->userinfo['userid'] always empty inside the forum, how can i use it?

    Hi,

    just recently converted our 170.000 posts phpBB to vBulletin and absolutely love it so far (conversion with impex went really smooth and the template and plugin system are priceless!). I just have one small problem:

    I cannot seem to use "$vbulletin->userinfo['userid']" in an include inside the forum. It is always empty.

    Explanation (simple version ):

    I include a file (blah.php) throughout the site, in this file i have

    PHP Code:
    <?
    echo $vbulletin->userinfo['userid'];
    ?>
    Outside the forum, i additionally have included the global.php:

    PHP Code:
    chdir($_SERVER['DOCUMENT_ROOT'].'/forum/'); 
    require(
    './global.php'); 
    chdir($_SERVER['DOCUMENT_ROOT']); 
    Inside the forum, i included the file with a plugin:

    Hook: global_start

    Code:
    ob_start();
    
    include('path/to/blah.php);
    $blah= ob_get_contents();
    ob_clean();
    
    include other stuff;
    ob_end_clean();
    and then output it in the first line of the header (templates system):

    Code:
    $blah
    Everywhere on our site, i get an output of my userid, just inside the forum the variable is empty and outputs nothing.

    How can i get it to echo my userid?

    (Longer explanation: I use a small login-thingie in the menu, which i can´t get to work in the forum. i am logged in in the normal login box, but not in the menu )

    thanks in advance,
    kopfnick
  • Jake Bunce
    Senior Member
    • Dec 2000
    • 46598
    • 3.6.x

    #2
    Normally you would use this variable directly in the templates:

    Code:
    $bbuserinfo[userid]

    Comment

    • kopfnick
      New Member
      • Dec 2005
      • 7

      #3
      Originally posted by Jake Bunce
      Normally you would use this variable directly in the templates:

      Code:
      $bbuserinfo[userid]
      Thanks, putting that in the template-header-box works, of course, but is there no way to output it inside an included php file?

      I mean, i could paste the whole menu-code into the template and try to get it to work, but that would mean havin 2 menus to maintain, which seems counter-productive

      BTW, did i really not give you any URL?
      You can find the site at www.hiphop.at/start (still in beta testing) and see the big menu on top...

      I also tried the following 3 lines in the included php file (really reaching for straws here ):

      PHP Code:
      $bbuserinfo[userid]
      <? $bbuserinfo[userid?>
      <? 
      echo $bbuserinfo[userid]; ?>
      Of course, neither one outputs the userid...

      Pleeeeeease have a solution for this, it really starts to bug me
      thx in advance,
      kopfnick

      Comment

      • Jake Bunce
        Senior Member
        • Dec 2000
        • 46598
        • 3.6.x

        #4
        It should work in included files. Maybe it isn't getting through to the output buffer when you call ob_start(). I have never tested scope with output buffers.

        You might try just including the file without a buffer, and then changing your code to evaluate the output to a variable instead of echoing it.

        Comment

        • kopfnick
          New Member
          • Dec 2005
          • 7

          #5
          Would try that in an instant, but it was hard enough finding out the "ob_start()" Stuff in just 2 days

          Could you maybe point me in the right direction how i would include it without a buffer?

          Thanks a million
          kopfnick

          Comment

          • kopfnick
            New Member
            • Dec 2005
            • 7

            #6
            Ok, after half a day of still fiddling around with this, i still have absolutely no solution.

            Is there any other way to achieve what i want to do?

            Pretty Please
            kopfnick

            Comment

            • kopfnick
              New Member
              • Dec 2005
              • 7

              #7
              Funny, now i just pasted the whole code form the included file - unchanged! - into the plugin, surrounded by the same ob_start and ob_end_clean and it works like a charm.

              It seems, that when i include the file, the variable doesn´t get parsed and gets no value.

              So for now i have a working solution with a little redundancy...
              Thanks anyway,
              kopfnick

              Comment

              • feldon23
                Senior Member
                • Nov 2001
                • 11291
                • 3.7.x

                #8
                Usually when someone is wanting to extend the functionality of an existing template through PHP, they grab the output buffer that already exists and do a search-and-replace through it either with str_replace or regex.

                More info at vBulletin.org.

                Comment

                • dcallan
                  Member
                  • Aug 2004
                  • 86
                  • 3.0.3

                  #9
                  kopfnick I know this issue is a couple of weeks in the past, but currenlty I'm having this issue too, the real but of including a nav file via the plugin system is that it only requires a change to one file. I too have included my include files in the header template like so:

                  $header
                  ....

                  echo
                  $leftnav

                  But am not able to access the bbuserinfo either from with that leftnav.php file that is included, so your saying your solution was to just paste your file directly into the template, so thats means having to update two different areas,

                  Is there a proper solution to this that anyone has found, perhaps it is to do with the ob clean() things.

                  ANy help much appreciated.

                  Comment

                  • feldon23
                    Senior Member
                    • Nov 2001
                    • 11291
                    • 3.7.x

                    #10
                    Although it has gotten better since vB2, there are still some cases in vBulletin where a variable isn't set until just before it is needed, which makes it difficult to rearrange the content of vB pages.

                    Here's a quick test to see if userid is set early enough to be used in header.

                    Open the header template and paste $bbuserinfo[userid]. Does the userid appear at the top of your forum? If not, then $bbuserinfo[userid] is not set until navbar and you'll have to hook into navbar.


                    Comment

                    • dcallan
                      Member
                      • Aug 2004
                      • 86
                      • 3.0.3

                      #11
                      The number 1 appears at the top of the screen. Thanks for your help by the way.

                      Comment

                      • dcallan
                        Member
                        • Aug 2004
                        • 86
                        • 3.0.3

                        #12
                        Sorry and when I log out 0 appears. But I cannot access these variables from within my leftnav.php file for some strange reason.

                        Comment

                        • dcallan
                          Member
                          • Aug 2004
                          • 86
                          • 3.0.3

                          #13
                          Wait Wait, I think I have got it to work now.
                          When I tried to access it via $vbulletin->userinfo['userid']; it worked
                          before I was just tring $bbuserinfo[userid] and nothing happend.

                          Perhaps one of the developers could mention this in the plugin documentation. Thanks for all your help.

                          Comment

                          • dcallan
                            Member
                            • Aug 2004
                            • 86
                            • 3.0.3

                            #14
                            A print_r($vbulletin); or a
                            print_r($vbulletin->userinfo) will list all the variables for the overall vb or for the current users. Just thought I'd share that for any future queries.

                            Comment

                            • feldon23
                              Senior Member
                              • Nov 2001
                              • 11291
                              • 3.7.x

                              #15
                              $bbuserinfo is apparently only available in templates.

                              Comment

                              widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                              Working...
                              😀
                              😂
                              🥰
                              😘
                              🤢
                              😎
                              😞
                              😡
                              👍
                              👎