vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Accessing user/cookie info outside of vBulletin (https://vborg.vbsupport.ru/showthread.php?t=170110)

Greg-J 02-10-2008 04:14 AM

Accessing user/cookie info outside of vBulletin
 
I'm creating a pseudo-marketplace outside of vbulletin and I'm running into a snag where I think many people do and I can't seem to find the solution I'm after.

I really need to be able to know if a user is logged into vbulletin and if they are, get their messages information, (userid, # of new/old messages etc.) and other things like the popup notification when they get a new message (although that's trivial at this point).

Any help would be much appreciated. I'm really just looking to know what vbulletin files/functions/classes I need to be using/including and any tips you might have the subject.

cheesegrits 02-10-2008 07:04 PM

There is a wealth of information on these forums and in the articles section covering this. Try searching for some obvious keywords.

Not being a smartass, just reminding you that "Search" is your friend. :)

-- hugh

Greg-J 02-11-2008 05:41 AM

I've searched and browsed quite a bit but I'm either not using the right keywords or they don't exist. I wouldn't have posted the question before I looked for the answer myself.

That said, the only in depth article I found involved doing this at the apache level which is not an appropriate solution for my application.

Again; any help would be much appreciated.

Dismounted 02-11-2008 06:53 AM

Include vBulletin's global.php. That will give you the essential functions including if the user is logged in or not.

Greg-J 02-12-2008 01:57 AM

Quote:

Originally Posted by Dismounted (Post 1440621)
Include vBulletin's global.php. That will give you the essential functions including if the user is logged in or not.

This seems to only work if you're including that file from within the same directory, which I am not. Even so, when I do move into the directory vB is installed and include the file I am presented with a no referrer error (not a big deal), but if I'm not logged in I get an odd mix of errors and partial html which just isn't going to work.

I apologize for the ignorance, but surely there must be hundreds of people who have done this and have documented it somewhere?

Dismounted 02-12-2008 04:20 AM

It has, and most times, the solution was posted by me ;).
PHP Code:

$curdir cwd();
chdir('./forum/');
require_once(
'/global.php');
chdir($curdir); 


Greg-J 02-12-2008 06:55 AM

Ahh, thank you.

Now, about the no http referrer/not logged in issues. Got anything for those? :)


UPDATE:

Your code must have been written on the fly ;) This is what works:

PHP Code:

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

Could still use some help on the bit about someone being logged in or not. Cheers.

Dismounted 02-12-2008 08:06 AM

Yes, sorry, I typed the code out, it would've taken longer for me to copy and paste :p.
PHP Code:

if (!empty($vbulletin->userinfo['userid']))
{
    
// user is logged in
}
else
{
    
// user is not logged in/guest



Greg-J 02-12-2008 07:55 PM

Cheers, but....


The issue isn't that the class is empty, it's that somewhere throughout the process in global.php. View this page to see what I mean:

http://www.myspacepros.com/_test.php

Dismounted 02-13-2008 04:06 AM

You might need to set the Cookie Domain/Path properly for it to recognise logged in users.

Greg-J 02-14-2008 11:00 AM

It recognizes logged in users fine. It's when you view the page when you're not logged in. The script doesn't even get all the way through global.php before it starts spitting out information...

cheesegrits 02-14-2008 03:12 PM

That link you posted works fine for me. Shows the link back to the page, and "not logged in".

-- hugh

Greg-J 02-18-2008 07:10 AM

Quote:

Originally Posted by cheesegrits (Post 1442966)
That link you posted works fine for me. Shows the link back to the page, and "not logged in".

-- hugh

Really?

This is what I get when navigating to that page while not logged in:

Code:

Notice: Undefined index: HTTP_REFERER in /var/www/vhosts/myspacepros.com/httpdocs/forum/includes/class_core.php on line 1574

Unable to add cookies, header already sent.
File: /var/www/vhosts/myspacepros.com/httpdocs/forum/includes/class_core.php
Line: 1574

I'm a bit lost now....

cheesegrits 02-18-2008 02:18 PM

That's because you have error reporting set to include notices in PHP. Which generates a 'notice' output if $_SERVER['HTTP_REFERER'] isn't set when vB tries to do this:

PHP Code:

        define('REFERRER',       $_SERVER['HTTP_REFERER']); 

When I hit the page, I'm clicking the link on this page first, so the HTTP_REFERER is set with the vborg page I'm being referred by. If you hit your page without being 'referred' by another page (i.e. type the URL in by hand in your browser), then HTTP_REFERER won't be set. And because the notice is being printed before vB sends the page headers, it screws up page output.

To fix that you'll need to turn off 'notice' level reporting in php.ini:

Code:

;  - Show all errors except for notices and coding standards warnings
;
error_reporting  =  E_ALL & ~E_NOTICE

Of course the real fix would be for vB to test for the existence of $_SERVER['HTTP_REFERER'] before using it in a define(), so if you want to go submit a bug report on vb.com ...

-- hugh

Greg-J 02-20-2008 12:10 AM

Thank you very much cheesegrits. I'm a little embarrassed I didn't think of that myself to be honest. Thank you.


All times are GMT. The time now is 06:22 AM.

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.01168 seconds
  • Memory Usage 1,753KB
  • 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
  • (2)bbcode_code_printable
  • (4)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (15)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