|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
persistant shopping card session destroy
Hi, I have built the "persistant shopping cart" in the tutorial and it works fine.
I want to however destroy the session when the user "checks out" but seem to be getting totally lost with it. The session cookie is passed from page to page using: function GetCartId() { // This function will generate an encrypted string and // will set it as a cookie using set_cookie. This will // also be used as the cookieId field in the cart table if(isset($_COOKIE["cartId"])) { return $_COOKIE["cartId"]; } else { // There is no cookie set. We will set the cookie // and return the value of the users session ID session_start(); setcookie("cartId", session_id()); return session_id(); } } which is stored in a file called db.php. The session is ended if they close the browser but i need to destroy it incase they don't as my orders table relies on unique cookie id's. Any help much appreciated |
|
#2
|
||||
|
||||
|
You should be able to do several things to help make this happen. First, check out session_unset() and session_destroy() and any other related functions at php.net. As these are sometimes flakey, you might also be able to set the cartId cookie again with a different value than the results of session_id() (for example, "NULL"). I'm not positive that one'll work, but it's worth a shot.
__________________
Please don't PM me asking for solutions outside the scope of a thread. Keeping all responses in a thread stands to help others who come along later, which is after all what this forum's all about. |
|
#3
|
|||
|
|||
|
I have had a look at manual and google and sort of think i am on the right track with this:
On the top of a new page i have this: <?php session_start(); session_unset (); session_destroy(); setcookie("cartId", "", time() - ((3600 * 24) * 2)); header ("location:stamps.php"); ?> however when i reload the cart the items are still there meaning that its either my mistake or some caching problem. What i am really unsure about is as i originally set a session_id can the session_unset recognise it if you see what i mean. |
|
#4
|
||||
|
||||
|
Maybe pass session_id() to session_unset() and session_destroy()?
I override the default session handler and stick my sessions in a database. This allows me to manually delete sessions when I want to, which lets me get around any flakiness in session_unset() and session_destroy(). Maybe you'd consider doing something like that? |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > persistant shopping card session destroy |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|