Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-12-2006, 03:58 PM
void void is offline
 
Join Date: Nov 2001
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default How to verify users group membership from VB cookie

Hi All,

I need to integrate the vb user/group system into a secondary php system.

The script should return the username if:

1. The users vb cookie is in a logged in state (dont know if it can exist and not be in a logged-in state).

2. The user is a member of a special group. (Hardcoded groupname)

Otherwise the script should return a blank and the receiving system will tell the visitor to log into VB first and/or join the appropiate group .

Oh, and the script should work across domains!, i.e. I need to return the user name or the blank to www.site1.com from www.site2.com.

Any ideas to the various levels in the above?

/Tim
Reply With Quote
  #2  
Old 01-19-2006, 03:07 PM
void void is offline
 
Join Date: Nov 2001
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok,

I made the following script

Script 1
PHP Code:
<?php
require_once('./global.php');  

$PRIVILIGED = array("5""6""7");        // Super Moderator, Admin, Moderator
$TRUSTED = array("9""10""11");        // Wiki, VIP, Special
$ALLOWED False;                    // Default not logged-in and not priviliged/trusted

// Check if user is logged in
if ($vbulletin->userinfo['userid']!=0
{
    if (
in_array($vbulletin->userinfo['usergroupid'], $PRIVILIGED)) 
        
$ALLOWED True;

    if (!
$ALLOWED)
    {
        
$memberships explode(',',$vbulletin->userinfo['membergroupids']); 
        foreach(
$memberships as $membership)
            if (
in_array($membership$TRUSTED)) 
            {
                
$ALLOWED True;
                break;
            }
    }
}

if (
$ALLOWED)
    
$var $vbulletin->userinfo['username'].','.$vbulletin->userinfo['userid'];
else
    
$var'no';

echo 
$var;
?>
This works fine when I execute it directly from my browser.

But I need to call script1 from another domain. Script1 above is actually placed in one subdomain like sub1.mysite.com and I need to call script1 from script2 in another subdomain like sub2.mysite.com.

Script 2
PHP Code:
<?php

ob_start
();
include 
'http://sub1.mysite.com/script1.php';
$contents ob_get_contents();
ob_end_clean();

echo 
$contents;
?>
But this fails!

When script 2 calls script 1 it echos "no" even though calling script1 directly returns a username and id. I found out that script1 fails at "
PHP Code:
if ($vbulletin->userinfo['userid']!=0
The VB3.53 has its cookie set to ".mysite.com", so that should be ok.

What am I missing here?
Reply With Quote
  #3  
Old 01-19-2006, 03:17 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Simpilfied code:
PHP Code:
<?php
require_once('./global.php');
if (
is_member_of($vbulletin->userinfo56791011))
{
    
$var $vbulletin->userinfo['username'].','.$vbulletin->userinfo['userid'];
}
else
{
    
$var 'no';
}
?>
Secondly, I don't understand why you need 2 Scripts.
If you use an include with an URL, the included script will never get cookies.
Also, for cookies to work across subdomains, your cookie-domain must be set to .mysite.com
Reply With Quote
  #4  
Old 01-19-2006, 04:23 PM
void void is offline
 
Join Date: Nov 2001
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Andreas
Simpilfied code:
I know. The script is a work in progress and I need to extend the needed differentiation later. I was stopped in my tracks by this problem


Quote:
Originally Posted by Andreas
Secondly, I don't understand why you need 2 Scripts.
I dont see how I can do it with 1 script. What are you suggesting here?

Quote:
Originally Posted by Andreas
If you use an include with an URL, the included script will never get cookies.
Why? Why should an included script not be able to access cookies that is availible to both sub domains?

Quote:
Originally Posted by Andreas
Also, for cookies to work across subdomains, your cookie-domain must be set to .mysite.com
As I stated in my previous post, it is.
Reply With Quote
  #5  
Old 01-19-2006, 05:17 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

When you do an include through an URL, the PHP process is the "browser" - and it does not have cookies

You would have to use fsockopen, curl or smth. to pass through the cookies.

But still I don't underestand why you don't just load the vBulletin backend where you need the data?
Reply With Quote
  #6  
Old 01-19-2006, 06:16 PM
void void is offline
 
Join Date: Nov 2001
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Andreas
When you do an include through an URL, the PHP process is the "browser" - and it does not have cookies
Bugger

Quote:
Originally Posted by Andreas
But still I don't underestand why you don't just load the vBulletin backend where you need the data?
You're most welcome to be elaborate. By all means! I'm no php/vb expert so I'm not sure I understand you correctly , but I cant share folders between the 2 sub domains. They dont necessarily run on the same webserver, so that I can connect them behind the lines. Or can I?

Can I require the global.php file from a script on subdomain 2 and run script 1 here instead?

Or do I have to disect the various VB scripts and extract userinfo initialization code into a standalone script that does not require a VB installation but only the cookie and the db?
Reply With Quote
  #7  
Old 01-19-2006, 06:29 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I assumed both subdomains are being hosted on the same phsical server (does not necessarily have to be the same webserver). If they are being run on separate machines, it gets more compicated - you could use NFS for example.

Or you could use a standalone login check (that's what I would do).

Or you could take the cookies and pass it (through a GET request for example) to the other server, process it and return if it's authorized or not).
Reply With Quote
  #8  
Old 01-20-2006, 06:51 AM
void void is offline
 
Join Date: Nov 2001
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Andreas,

I'll investigate the different approaches. Thx's for your efforts. It is much appreciated!

/Tim
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:19 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.03815 seconds
  • Memory Usage 2,253KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_php
  • (6)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete