Log in

View Full Version : How can I set a session variable?


Citizen
11-19-2006, 02:13 PM
I want to make a left column for navigation that is on every page of my site.

If my registered members click a button, I want the whole column to go away.

If they close out of the window and load the forums again, I want the column to be there again. (like a php session)

How can this be accomplished?

Guest190829
11-19-2006, 02:19 PM
I want to make a left column for navigation that is on every page of my site.

If my registered members click a button, I want the whole column to go away.

If they close out of the window and load the forums again, I want the column to be there again. (like a php session)

How can this be accomplished?

vBulletin has a special function for this called vbsetcookie():


void vbsetcookie (string $name, [mixed $value = ''], [boolean $permanent = true], [boolean $allowsecure = true], [boolean $httponly = false])

Citizen
11-19-2006, 02:22 PM
vBulletin has a special function for this called vbsetcookie():

What do the different attributes change?

Also, whats the easiest way to set a cookie with you want an option via button?

Guest190829
11-19-2006, 02:41 PM
Here is something I quickly wrote (not test yet)

Plugin: Sidebar Cookie
Hook Location: global_start

PHP Code:


$show['sidebar'] = true;

if ($_REQUEST['do'] == 'hidesidebar')
{
vbsetcookie('hidesidebar', 1, true);
}

$vbulletin->input->clean_gpc('c', 'hidesidebar', 'TYPE_INT');

if ($vbulletin->GPC['hidesidebar'] = 1)
{
$show['sidebar'] = false;
}


The template conditional would be:

<if condition="$show['sidebar']"> </if>

The button would point too:


?$session[sessionurl]do=hidesidebar

Citizen
11-19-2006, 02:54 PM
Thanks! Does execution order matter?

Also, do I need to change something here?

?$session[sessionurl]do=hidesidebar

Or just add make a link with this exact text:

forums/index.php?$session[sessionurl]do=hidesidebar

Guest190829
11-19-2006, 03:16 PM
Thanks! Does execution order matter?

Also, do I need to change something here?

?$session[sessionurl]do=hidesidebarOr just add make a link with this exact text:

forums/index.php?$session[sessionurl]do=hidesidebar

Execution should not matter, and you can do the following with the link:

{$vbulletin->options['bburl']}/index.php?$session[sessionurl]do=hidesidebar

Also I found a slight bug in the code from taking a second peak:


if ($vbulletin->GPC['hidesidebar'] = 1)


Should be:


if ($vbulletin->GPC['hidesidebar'] == 1)

Citizen
11-19-2006, 03:30 PM
Thanks!

Also, what template would I need to edit to put in a global left navigation bar?

Guest190829
11-19-2006, 03:32 PM
Thanks!

Also, what template would I need to edit to put in a global left navigation bar?

I wouldn't be able to say, depends on your style. My guess would be the navbar or header template.

Citizen
11-20-2006, 05:38 AM
Ok, so I've got my sidebar in and everything shows up great.

The only problem is I cant get the sidebar to go away when I click "Remove Sidebar" at the bottom of the sidebar

http://www.gunzfactor.com/forums

DiSpy
03-31-2007, 06:46 PM
Did you ever get this to work? I see on your forums that you are using this code, but I have to click the hide/show text 2x for it to work.

I can't even get it to do that using the above code?!?
THANKS!