简体   繁体   English

首次加载后设置phpsessid cookie

[英]set phpsessid cookie after first load

I'm making shared cart in opencart on two frontends with diferrent domains. 我正在使用不同域的两个前端在opencart中制作共享购物车。

I share the phpsessid to achieve that. 我共享phpsessid来实现这一目标。

Idea 理念

I pick some stuff on front-end 1 (abc.com), put it in the cart and then go to front-end 2 (xyz.com) go into the cart and pay there for example. 我在前端1(abc.com)上挑选了一些东西,放入购物车,然后转到前端2(xyz.com),进入购物车并在其中付款。

The problem is after the first load of the second front-end I see empty cart and i have to reload the page to change that. 问题是在第二个前端的第一次加载后,我看到空的购物车,我必须重新加载页面来更改它。 I see through my web developer that the phpsessid is set but is not accessible through $_COOKIE['PHPSESSID'] variable, but as i sad after reloading the page it works. 我通过我的Web开发人员看到phpsessid已设置,但无法通过$_COOKIE['PHPSESSID']变量进行访问,但是我很遗憾在重新加载页面后仍能正常工作。 Is there some workaround to make it work on first time i load the page? 有什么解决方法可以使它在我第一次加载页面时起作用?

Now i have set to reload the page after first visit, but i think it's quite filthy solution.. 现在,我准备在第一次访问后重新加载页面,但是我认为这是一个非常肮脏的解决方案。

The cookie is not yet set when you initially load the page on xyz.com. 最初在xyz.com上加载页面时,尚未设置cookie。 The cookie is delivered in the first payload, and is only accessible for reading after a round-trip is completed. cookie会在第一个有效负载中传递,并且只有在完成往返之后才能访问以读取。

If you must rely on cookie data, you will need to set the cookie in an initial page load, then immediately redirect to your shopping cart frontend that the user sees. 如果必须依靠Cookie数据,则需要在初始页面加载中设置Cookie,然后立即重定向到用户看到的购物车前端。 The cookie data will be set during the first page, and then the values can be displayed on the second. Cookie数据将在第一页设置,然后在第二页显示这些值。

You can use Javascript to complete this redirect if necessary. 如有必要,您可以使用Javascript完成此重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM