Zen Cart Logo
Forums / General Questions / how to add a new session variable?

how to add a new session variable?

Views: 2,440

Results 1 to 12 of 12
21 Sep 2011, 11:56 AM
#1
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

how to add a new session variable?

Drawing a blank here and I don't know if this is a zen cart question or a php question or both.

I want to add a session variable for both guest and logged in user. How/where would I do that?

21 Sep 2011, 2:33 PM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: how to add a new session variable?

What do you want to do with the session variable?

A hint would make this easier ... :unsure:

21 Sep 2011, 3:20 PM
#3
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Re: how to add a new session variable?

Ah, sorry. (I seem to be always apologizing on the forum when I post questions!)

I'm looking to set up the columns vs rows scenario for the product listing as a changeable thing for anyone. They will be able to change the listing display at will simply by clicking a button.

So I would need the session variable to be present immediately on site entry, I assume.

21 Sep 2011, 3:56 PM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: how to add a new session variable?

You could probably add it to the bottom of the:
/includes/init_includes/init_session.php

with something like:

// bof: set $_SESSION['my_session_variable'] if not previously set
if (!isset($_SESSION['my_session_variable'])) {
  $_SESSION['my_session_variable'] = 'something';
}
// eof: set $_SESSION['my_session_variable'] if not previously set
21 Sep 2011, 5:53 PM
#5
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Re: how to add a new session variable?

Thanks, Linda!

21 Sep 2011, 5:54 PM
#6
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: how to add a new session variable?

Sure thing ... thanks for the update that this can work for you ... :smile:

21 Sep 2011, 7:51 PM
#7
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: how to add a new session variable?

In the interest of preventing clashes with core files, I'd suggest putting it in its own file, in two steps, like this:

a) /includes/auto_loaders/config.your_mod_name.php```

<?php $autoLoadConfig[115][] = array('autoType'=>'init_script', 'loadFile'=> 'init_my_custom_init_code_here.php'); ``` b) /includes/init_includes/init_my_custom_init_code_here.php``` whatever session code or other stuff you need to run ```
21 Sep 2011, 7:52 PM
#8
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Re: how to add a new session variable?

Oh, good, I need that!

21 Sep 2011, 8:18 PM
#9
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Re: how to add a new session variable?

I can't tell you how powerful that makes me feel! It worked!

21 Sep 2011, 8:25 PM
#10
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: how to add a new session variable?

:clap: :D

12 Oct 2011, 1:58 PM
#11
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Re: how to add a new session variable?

Okay, so the next question is what would make this not work? I got the mod finished and working on a default install and then went to install it on the customer's cart. The session variable is not being added to the session.

There are some mods installed, most importantly the single listing template which of course affects the product_list.php.

But I did substitute the normal one and saw no change.

So what would prevent the session initialization from working?

13 Oct 2011, 1:51 PM
#12
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Re: how to add a new session variable?

One more bit of information: the only difference with sessions between the problem server and my server is that on his the session.use_only_cookies is turned off. Our zen cart settings for session are the same except the ssl session id:

Cookie Domain True Info
Force Cookie Use False Info
Check SSL Session ID True
Check User Agent False Info
Check IP Address False Info
Prevent Spider Sessions True Info
Recreate Session True Info
IP to Host Conversion Status true Info
Use root path for cookie path False Info
Add period prefix to cookie domain True