Shopping cart persistence: $_SESSION or browser cookie?

前端 未结 6 621
天命终不由人
天命终不由人 2021-01-30 03:34

On an e-commerce site with no username/login to persist cart data, would it be better to use the PHP $_SESSION variable or a browser cookie to persist items in the shopping cart

6条回答
  •  情话喂你
    2021-01-30 04:04

    You might consider using both.

    The drawback with $_SESSION is that the session is cleared when the browser is closed.

    Use sessions, but attempt to populate the $_SESSION data from a cookie, if it's available.

提交回复
热议问题