vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   $vbulletin->userinfo['userid'] always returns 0 (https://vborg.vbsupport.ru/showthread.php?t=265887)

codeit 06-27-2011 08:36 PM

$vbulletin->userinfo['userid'] always returns 0
 
I'm trying to integrate a vb login form on my homepage but couldn't find no help so far.. even posted a question here last week but getting no answer. so I'm doing some experiments to find the way on my own...

For now, I'm having a test.php page which located at an upper directory of my forums, and include the forums' global.php file, just to be able to access the $vbulletin->userinfo data. However, $vbulletin->userinfo['userid'] always returns 0 as an Unregistered user even when I logged in.

I took the code to my local pc (running IIS) and it works just fine (of course I had to change the path due to Windows v.s Unix, but can't figure out why it doesn't work on my Unix host..

Here's a sort of my experiment code:

Code:

$curdir = getcwd();
chdir($curdir.'/forums');
require_once('./global.php');

//Use $bbuserinfo.
echo('userid: ' . $vbulletin->userinfo['userid']);
echo('userid: ' . $vbulletin->userinfo['username']);
chdir($curdir);

Also, everytime I access this test.php page, it kicks out my login status on vbulletin.

Please help
Thanks

Boofo 06-27-2011 08:46 PM

Did you try $bbuserinfo['userid']?

codeit 06-27-2011 08:50 PM

yeah I did.. in fact, you can see my note there to use $bbuserinfo at first.. then I gave up with it and try $vbulletin ->userinfo...
$bbuserinfo['userid'] returns nothing, not even 0

borbole 06-27-2011 09:00 PM

Can you post the whole code of your test.php page?

Adrian Schneider 06-27-2011 09:02 PM

Same cookie domain + path?

codeit 06-27-2011 09:07 PM

Borbole: it's pretty much the whole code.. except the <?php tags.. here it is everything again (just a very simple code):

Code:

<?php //test.php

$curdir = getcwd();
chdir($curdir.'/forums');
require_once('./global.php');

//Use $bbuserinfo.
echo('userid: ' . $vbulletin->userinfo['userid']);
echo('userid: ' . $vbulletin->userinfo['username']);
chdir($curdir);

?>

Adrian:
Your comment kindda made me think.. but I believe it is, cuz this test.php is on the same host and everything, just on an upper dir of the forums, and I'm accessing both (the forums and the test.php) on the same browser...

kh99 06-27-2011 09:10 PM

FWIW I tried this on a linux host and it worked. Dumb question, but are you testing it with the same browser that you're logging in to vb with? (Sometimes I have IE and FF going at the same time).

codeit 06-27-2011 09:14 PM

Yes, I basically have 2 tabs on my browser, one with vb, and the other with the test page.. login to the vb, then refresh the test page and it shows 0 for userid and Unregistered for username. Then go back to vb, it.. logged me out.

Also tried with IE since I have both IE and FF. same thing

Boofo 06-27-2011 09:20 PM

Try changing this:

chdir($curdir.'/forums');

to this:

chdir($curdir'./forums');

codeit 06-27-2011 09:26 PM

Boofo:
that gives a syntax error
Code:

syntax error, unexpected T_CONSTANT_ENCAPSED_STRING
and
chdir($curdir.'./forums');
gives a "no such file or directory" error

Boofo 06-27-2011 09:36 PM

Look closer at my change. I didn't add the first dot.

codeit 06-27-2011 09:42 PM

Boofo:
I knew that.. the first part of my previous reply about the syntax error was for the exact change you gave, then I just tried a little more than what you suggested.. sorry didn't make it clear enough.

It's for sure a directory issue, I just tried to move test.php into the forums directory and removed the chdir stuffs and it works, so must be the chdir stuffs...

kh99 06-27-2011 09:45 PM

In the ACP under "Cookies and HTTP Header Options", what do you have "Path to Save Cookies" set to? According to the help for that option, unless you have it set to '/', the cookies won't work in other directories. (I guess that's what Adrian meant by "path").

codeit 06-27-2011 09:57 PM

YES! I just got it.. damn it
kh99: you're just right on, I actually just found out by comparing the settings on the two hosts, then got it to work.. then came back here and see your post exactly the same as what I found.

I recently moved my boards to vB so I'm still new to it, these little things will kill me more :)

Thank you all for your helps.

Adrian Schneider 06-27-2011 10:00 PM

Glad to hear you figured it out. :)

kh99 06-27-2011 10:24 PM

You got it in one, it just took us a bit to catch up with you. ;)

Boofo 06-27-2011 11:13 PM

I was way off.

codeit 06-28-2011 04:33 AM

Although replies don't answer the question directly sometimes, they contribute to the brainstorming :)
So.. they're all appreciated.

LT Mote 06-28-2011 07:59 AM

Quote:

Originally Posted by Boofo (Post 2213712)
Did you try $bbuserinfo['userid']?

" $bbuserinfo['userid'] " doesn't work on 4.x

socialteenz 06-28-2011 12:36 PM

Did you try?

{vb:raw userinfo.fieldx}

HMBeaty 06-28-2011 12:43 PM

Quote:

Originally Posted by socialteenz (Post 2214042)
Did you try?

{vb:raw userinfo.fieldx}

What does that have to do with anything? :confused:

BirdOPrey5 06-28-2011 12:44 PM

Quote:

Originally Posted by socialteenz (Post 2214042)
Did you try?

{vb:raw userinfo.fieldx}

That code only works in a template. This is raw php code.

$vbulletin->userinfo['userid'] is the correct variable to use... why it's not working is the issue... probably a cookie thing, the user is being logged out/has no session on the custom page.

Did you declare $vulletin to be global?

HMBeaty 06-28-2011 12:48 PM

Quote:

Originally Posted by BirdOPrey5 (Post 2214046)
That code only works in a template. This is raw php code.

$vbulletin->userinfo['userid'] is the correct variable to use... why it's not working is the issue... probably a cookie thing, the user is being logged out/has no session on the custom page.

Did you declare $vulletin to be global?

And the code posted by socialteenz
HTML Code:

{vb:raw userinfo.fieldx}
pulls the info from a user profile field for a template lol

kh99 06-28-2011 12:57 PM

In case anyone cares, the OP solved the problem 10 posts ago, it was the cookie path (and there was nothing wrong with the original code) :)

HMBeaty 06-28-2011 12:59 PM

Quote:

Originally Posted by kh99 (Post 2214055)
In case anyone cares, the OP solved the problem 10 posts ago, it was the cookie path (and there was nothing wrong with the original code) :)

https://vborg.vbsupport.ru/external/2011/06/9.jpg

socialteenz 06-28-2011 01:01 PM

Quote:

Originally Posted by HMBeaty (Post 2214050)
And the code posted by socialteenz
HTML Code:

{vb:raw userinfo.fieldx}
pulls the info from a user profile field for a template lol

My bad, it was supposed to be

Code:

{vb:raw userinfo.userid}

HMBeaty 06-28-2011 01:02 PM

Quote:

Originally Posted by socialteenz (Post 2214058)
My bad, it was supposed to be

Ah, that makes a little more sense, but still for a template :D

socialteenz 06-28-2011 01:10 PM

Quote:

Originally Posted by HMBeaty (Post 2214060)
Ah, that makes a little more sense, but still for a template :D

yeah, i didn't read the thread properly though.


All times are GMT. The time now is 01:00 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01367 seconds
  • Memory Usage 1,774KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code_printable
  • (2)bbcode_html_printable
  • (8)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (28)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete