简体   繁体   中英

set phpsessid cookie after first load

I'm making shared cart in opencart on two frontends with diferrent domains.

I share the phpsessid to achieve that.

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.

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. 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. The cookie is delivered in the first payload, and is only accessible for reading after a round-trip is completed.

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. The cookie data will be set during the first page, and then the values can be displayed on the second.

You can use Javascript to complete this redirect if necessary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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