Zen Cart Logo
Forums / General Questions / trying to understand SESSION_FORCE_COOKIE_USE

trying to understand SESSION_FORCE_COOKIE_USE

Views: 4,993

Results 1 to 18 of 18
9 Jul 2020, 11:41 PM
#1
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,956
Plugin Contributions:
8

trying to understand SESSION_FORCE_COOKIE_USE

i have read a bunch on this, and i still trying to understand this config value.

allow me to give an example, i'm creating a new script that will add a particular product to a cart; and then the bring the user to the shopping cart page. this link would be used in a marketing email. however, if SESSION_FORCE_COOKIE_USE is set to TRUE, it will not work, as the session only gets set on the 2nd click on a particular site. the code is from here:

includes/init_includes/init_sessions.php

if (SESSION_FORCE_COOKIE_USE == 'True') {
  setcookie('cookie_test', 'please_accept_for_session', time()+60*60*24*30, $path, (zen_not_null($cookieDomain) ? $domainPrefix . $cookieDomain : ''), $secureFlag);

  if (isset($_COOKIE['cookie_test'])) {
    zen_session_start();
    $session_started = true;
  }

setcookie returns true or false (not indicative of whether the user accepts the cookie, just that is was properly set). but we choose not to use that return value. so that it is only on the 2nd click that the session gets started assuming that the user has accepted the cookie.

now, if a user decides to not accept cookies, that is one thing. if you do not accept cookies, i think you are limited in your shopping experience that one can do.

now there also seems to be some code if this value is set to FALSE, and you have different domains for your NON SSL site v your SSL site; ie http://mysite.com and https://www.mysite.com, ZC will append the session id to the url as a _GET var.

my question is what is the real implication of setting this var to False? and what is the point of waiting to see if the user has accepted the cookie in order that we start the session?

thanks in advance.

10 Jul 2020, 5:24 AM
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: trying to understand SESSION_FORCE_COOKIE_USE

So to be clear, default setting is false.
When false, a session is "maintained" by whatever means necessary basically. Basically attempt to set a cookie, if not successful then retain the session on the url.

Impact? When set to false, spiders can be (though don't have to be) filtered by the information they provide. The session is started out right and later as urls are generated, the session info is added to the url provided that as described some characteristics are met where it may be expected that the session id would change.

As to the pause on the cookie aspect, I see it as how can one claim that the session information is being tracked by a cookie and therefore that when forcing cookie usage that it is in use if one doesn't first validate that the cookie is being used? Until then, there are a few pages that can't directly be visited because afterall need some sort of session.

My 2 cents.

10 Jul 2020, 10:07 PM
#3
drbyte avatar

drbyte

Sensei

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

Re: trying to understand SESSION_FORCE_COOKIE_USE

carlwhat:

i'm creating a new script that will add a particular product to a cart; and then the bring the user to the shopping cart page. this link would be used in a marketing email

It feels like you're over-complicating things.
Why do you need a new script?

In a fresh install, simply calling example.com/index.php?main_page=any_valid_page&action=buy_now&products_id=168 will add the item to the cart and go to the shopping-cart page.

10 Jul 2020, 11:13 PM
#4
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,956
Plugin Contributions:
8

Re: trying to understand SESSION_FORCE_COOKIE_USE

DrByte:

It feels like you're over-complicating things.
Why do you need a new script?

In a fresh install, simply calling example.com/index.php?main_page=any_valid_page&action=buy_now&products_id=168 will add the item to the cart and go to the shopping-cart page.

ok, allow me to back up a bit.

  • it's not a new script.
  • the site has moved to a new server.
  • the script worked on the old server.
  • its not working on the new server.
  • i tracked my initial problem down to sessions.
  • i did not know/think about the link that you generated/created (learn something new every day).
  • the link you provided is doing the exact same behavior (a bug that i am trying to fix) as my script.
  • once your url link is constructed, if you paste the url into a browser window, it works fine.
  • if you click the link from an email, you get to the shopping cart and there is nothing there.
  • i have tested using http: and https:; both links demonstrate the same behavior. the site is completely https.
  • it suggests to me a problem with the server config.

i'm open to suggestions....

thanks in advance.

11 Jul 2020, 4:12 PM
#5
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,956
Plugin Contributions:
8

Re: trying to understand SESSION_FORCE_COOKIE_USE

i am making some headway, but it still gets quite confusing. i have shorted the link at as such:

mysite.com/shopping_cart?action=buy_now&products_id=11922

when i look at the sessions table, i now have the following data (security token removed and sesskey truncated):

-------->22g1tbpufd1gt7qq4.....<--------- 2020-07-11 09:07:45
securityToken|s:32:"...";customers_host_address|s:35:"cpe-172-117-255-16.socal.res.rr.com";cartID|s:0:"";cart|O:12:"shoppingCart":13:{s:8:"contents";a:1:{i:11922;a:1:{s:3:"qty";d:1;}}s:5:"total";i:0;s:6:"weight";i:0;s:6:"cartID";s:5:"27217";s:12:"content_type";b:0;s:18:"free_shipping_item";i:0;s:20:"free_shipping_weight";i:0;s:19:"free_shipping_price";i:0;s:14:"download_count";i:0;s:22:"total_before_discounts";i:0;s:22:"display_debug_messages";b:0;s:23:"flag_duplicate_msgs_set";b:0;s:32:"flag_duplicate_quantity_msgs_set";b:0;}check_valid|s:4:"true";navigation|O:17:"navigationHistory":2:{s:4:"path";a:1:{i:0;a:4:{s:4:"page";s:13:"shopping_cart";s:4:"mode";s:3:"SSL";s:3:"get";a:2:{s:6:"action";s:7:"buy_now";s:11:"products_id";s:5:"11922";}s:4:"post";a:0:{}}}s:8:"snapshot";a:0:{}}language|s:7:"english";languages_id|s:1:"1";languages_code|s:2:"en";layoutType|s:6:"legacy";currency|s:3:"USD";new_products_id_in_cart|s:5:"11922";analytics|a:2:{s:6:"action";s:11:"Add to Cart";s:4:"item";a:6:{s:9:"productID";i:11922;s:11:"productName";s:20:"2010 Chateau Hosanna";s:8:"category";s:19:"Bordeaux Red";s:5:"brand";s:15:"Chateau Hosanna";s:10:"productQTY";i:1;s:7:"variant";s:3:"n/a";}}


-------->dsg59kfhre9uq3c68i....<--------- 2020-07-11 09:07:45
securityToken|s:32:"...";customers_host_address|s:35:"cpe-172-117-255-16.socal.res.rr.com";cartID|s:0:"";cart|O:12:"shoppingCart":12:{s:8:"contents";a:0:{}s:5:"total";i:0;s:6:"weight";i:0;s:12:"content_type";b:0;s:18:"free_shipping_item";i:0;s:20:"free_shipping_weight";i:0;s:19:"free_shipping_price";i:0;s:14:"download_count";i:0;s:22:"total_before_discounts";i:0;s:22:"display_debug_messages";b:0;s:23:"flag_duplicate_msgs_set";b:0;s:32:"flag_duplicate_quantity_msgs_set";b:0;}check_valid|s:4:"true";navigation|O:17:"navigationHistory":2:{s:4:"path";a:1:{i:0;a:4:{s:4:"page";s:13:"shopping_cart";s:4:"mode";s:3:"SSL";s:3:"get";a:0:{}s:4:"post";a:0:{}}}s:8:"snapshot";a:0:{}}language|s:7:"english";languages_id|s:1:"1";languages_code|s:2:"en";layoutType|s:6:"legacy";currency|s:3:"USD";today_is|s:10:"2020-07-11";updateExpirations|b:1;session_counter|b:1;customers_ip_address|s:14:"172.117.255.16";valid_to_checkout|b:1;cart_errors|s:0:"";

the first session has the shopping cart. but the browser now has the second session key as the zenid cookie. so a new session is getting created after the item is added to the cart. and i'm trying to figure out how/why.

appreciate any help.

11 Jul 2020, 7:42 PM
#6
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Location:
Newcastle UK
Posts:
1,850
Plugin Contributions:
3

Re: trying to understand SESSION_FORCE_COOKIE_USE

One of the main reasons that SESSION_FORCE_COOKIE_USE fails is some incorrect server configuration.
Usually a mismatch between your websites domain and it's actual host address.

You say that the code you are working on runs fine without SESSION_FORCE_COOKIE_USE
Do you see a zenid in your urls ?
Can you use a browser tool (such as firefox web developer storage inspector) to examine any cookies that Zen Cart is setting/trying to set.
look at the Cookie Domain and Cookie Path. Do the setting make sense for your site.

11 Jul 2020, 9:34 PM
#7
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,956
Plugin Contributions:
8

Re: trying to understand SESSION_FORCE_COOKIE_USE

wilt:

One of the main reasons that SESSION_FORCE_COOKIE_USE fails is some incorrect server configuration.
Usually a mismatch between your websites domain and it's actual host address.

You say that the code you are working on runs fine without SESSION_FORCE_COOKIE_USE
Do you see a zenid in your urls ?
Can you use a browser tool (such as firefox web developer storage inspector) to examine any cookies that Zen Cart is setting/trying to set.
look at the Cookie Domain and Cookie Path. Do the setting make sense for your site.

wilt,
thanks for taking a look.

here's what i have so far:

  • SESSION_FORCE_COOKIE_USE is set to false
  • pretty sure the problem does not lie there
  • there are 2 sessions getting created and inserted into the sessions table for 1 click of the link.
  • session.auto_start is set to false; plus i see there are ZC auto start warnings that are not getting triggered.
  • the zenid is not in the url.
  • when i examine the cookies, the cookie domain looks ok. there is no www; and it starts with a period. but the server is configured to route all www traffic to mydomain.com. plus the link is mydomain.com.
  • all of the cookie paths are set to a single slash (/).
  • not really sure what you mean by a mismatch between the websites domain and actual host address. are you suggesting a dns problem? a hostname problem? not sure how the host name would be a problem. i host multiple domains on this server. my test server has 5 different virtual hosts; that server does not exhibit the same behavior.
  • if you could be clearer, i can explore and let you know.

thanks again for the help.

best.

12 Jul 2020, 4:35 AM
#8
drbyte avatar

drbyte

Sensei

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

Re: trying to understand SESSION_FORCE_COOKIE_USE

carlwhat:

  • not really sure what you mean by a mismatch between the websites domain and actual host address.

eg: HTTP_SERVER = example.com
but server vhost = https://www.example.com

12 Jul 2020, 5:42 AM
#9
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,956
Plugin Contributions:
8

Re: trying to understand SESSION_FORCE_COOKIE_USE

from zc configure file:

define('HTTP_SERVER', 'https://example.com');
define('HTTPS_SERVER', 'https://example.com');

from /etc/apache2/sites-available files:

ServerName  example.com
ServerAlias  www.example.com

the above is the same for the non vhost on port 80 as well as the vhost on port 443.

12 Jul 2020, 7:08 PM
#10
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,956
Plugin Contributions:
8

Re: trying to understand SESSION_FORCE_COOKIE_USE

i think i have finally solved this problem.

the server enforced a samesite setting of strict on the cookies. changing this setting to Lax resolved the issue.

again, thanks for the help. it was appreciated.

best.

4 Apr 2021, 2:50 PM
#11
4tinak avatar

4tinak

New Zenner

Join Date:
Sep 2020
Location:
Arizona
Posts:
29
Plugin Contributions:
0

Re: trying to understand SESSION_FORCE_COOKIE_USE

I am trying to isolate an issue with a website - I believe it is a sessions issue.
Customer can log in -no problem.
Clicking any link other than the home link cart acts like it should.
Clicking a home link (header, footer, and nav cat area) shows customer logged out.
Clicking log in again, takes customer to purchase history page.
Also - noted once logged in, after navigating a few pages, customer is logged out again.
Server settings for sessions is attached. Are these correct?

Attachment 19501

Site is version 1.5.6c running ph 7.3.27
Upgraded: - all done as manual upgrades, not through one-click install
v1.5.6c [2020-01-20 13:12:49] (Version Update 1.5.5->1.5.6c)
v1.5.5f [2020-01-20 13:12:47] (Version Update 1.5.4->1.5.5f)
v1.5.4 [2016-06-19 01:44:12] (Version Update 1.5.3->1.5.4)
v1.5.3 [2016-06-19 01:44:12] (Version Update 1.5.2->1.5.3)
v1.5.2 [2016-06-19 01:44:12] (Version Update 1.5.1->1.5.2)
v1.5.1 [2013-10-13 13:44:41] (Version Update 1.5.0->1.5.1)
v1.5.0 [2013-10-13 13:44:29] (Version Update 1.3.9->1.5.0)
v1.3.9h [2013-10-13 13:44:13] (Version Update 1.3.8->1.3.9h)
v1.3.8 [2009-09-07 11:57:32] (Fresh Installation)
v1.3.8 [2009-09-07 11:57:32] (Fresh Installation)

Any help is greatly appreciated!

4 Apr 2021, 3:20 PM
#12
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,080
Plugin Contributions:
56

Re: trying to understand SESSION_FORCE_COOKIE_USE

@4tinak, who's your webhost?

5 Apr 2021, 1:57 PM
#13
4tinak avatar

4tinak

New Zenner

Join Date:
Sep 2020
Location:
Arizona
Posts:
29
Plugin Contributions:
0

Re: trying to understand SESSION_FORCE_COOKIE_USE

Host is siteground

5 Apr 2021, 3:28 PM
#15
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,956
Plugin Contributions:
8

Re: trying to understand SESSION_FORCE_COOKIE_USE

4tinak:

Host is siteground

bravo @lat9.

5 Apr 2021, 5:40 PM
#16
4tinak avatar

4tinak

New Zenner

Join Date:
Sep 2020
Location:
Arizona
Posts:
29
Plugin Contributions:
0

Re: trying to understand SESSION_FORCE_COOKIE_USE

lat9:

See this posting for a solution: https://www.zen-cart.com/showthread.php?227913-v157b-quot-Your-Shopping-Cart-is-Empty-quot-but-only-in-some-browsers-and-not-Incognito&p=1379562

I implemented this - no joy.

Note, there was no cPanel but I was able to turn off NGINX cache - no option to clear cache.

5 Apr 2021, 6:02 PM
#17
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,080
Plugin Contributions:
56

Re: trying to understand SESSION_FORCE_COOKIE_USE

4tinak:

I implemented this - no joy.

Note, there was no cPanel but I was able to turn off NGINX cache - no option to clear cache.

  1. Log into your siteground account.
  2. Click the WEBSITES tab at the top.
  3. Click the SITE TOOLS button.
  4. On the left-side pane, click Speed, then Caching
  5. Turn the NGINX DIRECT DELIVERY switch to its 'off' position.
  6. Click the DYNAMIC CACHE tab
  7. Click the little 'broom' icon to clear the cache.
  8. Edit your site's main .htaccess file, adding the following to the top of the file and save.
<IfModule mod_headers.c>
Header set Cache-Control "max-age=0,no-store"
</IfModule>

Click again on the little 'broom' icon.

If you're still having issues, it might be that your browser has, itself, cached the results. On a Windows-based browser, hold the Ctrl key down and either press F5 or click the 'Reload' icon at the top of the page.

5 Apr 2021, 8:13 PM
#18
4tinak avatar

4tinak

New Zenner

Join Date:
Sep 2020
Location:
Arizona
Posts:
29
Plugin Contributions:
0

Re: trying to understand SESSION_FORCE_COOKIE_USE

lat9:

  1. Log into your siteground account.
  1. Click the WEBSITES tab at the top.
  1. Click the SITE TOOLS button.
  1. On the left-side pane, click Speed, then Caching
  1. Turn the NGINX DIRECT DELIVERY switch to its 'off' position.
  1. Click the DYNAMIC CACHE tab
  1. Click the little 'broom' icon to clear the cache.
  1. Edit your site's main .htaccess file, adding the following to the top of the file and save.
<IfModule mod_headers.c> Header set Cache-Control "max-age=0,no-store" </IfModule> ``` > > Click again on the little 'broom' icon. > > If you're still having issues, it might be that your browser has, itself, cached the results. On a Windows-based browser, hold the Ctrl key down and either press F5 or click the 'Reload' icon at the top of the page.

Thank you for the step-by-step.
I did each step and all seems ok.

I'll check the site later to verify it "stays" fixed.

Thanks again for your help!