PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old August 4th, 2004, 11:24 AM
devey devey is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 9 devey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old August 4th, 2004, 11:59 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
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.

Reply With Quote
  #3  
Old August 5th, 2004, 10:13 AM
devey devey is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 9 devey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #4  
Old August 5th, 2004, 12:32 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
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?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > persistant shopping card session destroy


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway