PDA

View Full Version : Using sessions or cookies from vBulletin


josh_krz
08-23-2012, 02:43 PM
I was just wondering if it is possible to use cookies or sessions from vBulletin on a non vB page on my website.

I would like to disable a webpage to people in a certain usergroup, is this possible?

Ideally I would like to use template variables with my vB header etc. but every solution I come across just seems so overly complicated.

Thank you.

kh99
08-23-2012, 02:49 PM
You'd have to do something like this: https://vborg.vbsupport.ru/showthread.php?t=228112 . If your non-vb pages are php, then you might be able to include global.php without doing everything that that article shows (if you just wanted the user's group, for instance). But if you mean html pages, then you'd have to create a php page like is shown in that article, and either put in php code to read your html file and return it (after checking the user's group), or else put your html in a template. (I hope this makes some sense - please ask for clarification if it doesn't :) )

josh_krz
08-23-2012, 02:58 PM
That article is great, could you elaborate more on using global.php please?

So like, when I include that file, do I just use the template variables as normal or is there a different way of using them?

Thank you.

kh99
08-23-2012, 03:06 PM
That article is great, could you elaborate more on using global.php please?

If you did nothing other than include the vbulletin global.php, you'd be able to use $vbulletin to do things like check if the user is logged in or which group they're in. There are a couple of issues: one is that the current directory needs to be the forum directory (the one global.php is in) before you include it, so if your script is in another directory you need to chdir() to the vb directory first. Also, the user will only appear as logged in if the vb cookies are sent, so if your script is outside the vb directory, the vb cookie path needs to be set to '/' or else it will always look like the user is a guest.


So like, when I include that file, do I just use the template variables as normal or is there a different way of using them?

I'm not quite sure I follow. I guess it depends on which variables you want. They may be available just by including global.php, or you might need to find the code that calculates them. I'm also not sure if you mean you want to use templates, or if you just want the info in the variables. If you want to use templates, you probably should just use what's shown in that article as a guide.

josh_krz
08-23-2012, 03:12 PM
Sorry I explained it in a bad way.

What I mean is will I be able to use <vb:if condition="$vboptions['enablesearches']"> inside that PHP file?

Or do you use it like so;

if ($vboptions['enablesearches'] == true;){
//Show search bar;
}

kh99
08-23-2012, 03:15 PM
You could use this:

if ($vbulletin->options['enablesearches'] == true){
//Show search bar;
}



To be honest I'm not sure about $vboptions - it's a shortcut variable equivalent to $vbulletin->options that's created for use in templates, but I'm not sure if it's defined outside of a template.

josh_krz
08-23-2012, 03:19 PM
Ok thanks, Ill have a go at that and see what's what.

kh99
08-23-2012, 03:23 PM
Yeah, my "edit" above (which I removed) may have been wrong - I'm not sure if you can use $vboptions or not - I'd have to do a test (or maybe someone else will know).