Page 1 of 1
destroying a session help
Posted: Wed Apr 27, 2005 1:28 am
by C_Calav
hi guys,
i have this piece of code
Code: Select all
ob_start();
session_start();
$_SESSION = array(); // unset all of the session variables
session_destroy();
unset($cartId);
to destroy this session
Code: Select all
// There is no cookie set. We will set the cookie
// and return the value of the users session ID
setcookie("cartId", session_id(), time() + (3600));
return session_id();
now theoretically, if i go to my cart after i have been to a page with the destroy session code on it, i should have no items in my cart right?
or am i wrong.... ?
i dont think my session is getting destroyed as i still have items in cart (and i can see it in my database, as i am adding it)
can anyone help me out with destroying my session when the user goes to a certain page??
thanx heaps
Posted: Thu Apr 28, 2005 8:09 pm
by C_Calav
should i re-phrase my question?
Posted: Thu Apr 28, 2005 8:25 pm
by John Cartwright
Yes
Posted: Thu Apr 28, 2005 9:05 pm
by C_Calav
on my website
http://www.deskjetmodels.co.nz when you add a item to the cart you get issued with a cookieID.
now that cookieID holds your items in your cart.
after the user has completed a order and the transaction is approved i want the users shopping cart to be empty and the cookieID cleard.
i want this to happen because if they make another order they will still have the same cookieID.
my question is how do i clear the users cookieID and start off 'fresh' again like they have just visted the site for the first time.
thanx.
i have some code supplied above, that i have in place at the moment to try and do this
Posted: Fri Apr 29, 2005 12:04 am
by hongco
you have set a cookie
Code: Select all
setcookie("cartId", session_id(), time() + (3600));
now, you need to delete it by setting the cookie past the time of the cookie being first created - by setting it back to an hour ago; hence, the cookie is expired.
Code: Select all
setcookie("cartId", session_id(), time() - (3600));
Posted: Sun May 01, 2005 4:07 am
by C_Calav
hi there,
thanx for your reply hongco.
i put your bit of code at the top of the page where i want the session to end.
Code: Select all
ob_start();
setcookie("cartId", session_id(), time() - (3600));
and it doesnt seem to be working. the user still has the same session running
any idea's?
Posted: Sun May 01, 2005 10:55 am
by Chris Corbyn
You'll need to delete the cookie / destroy the session and the refresh the browser.
A better method than refreshing is to point to a destroy.php script which destroys the session and then uses a header() to send the user back to the required location.
Posted: Mon May 02, 2005 12:46 am
by C_Calav
hi thanx for your reply,
im having a bit of trouble trying to get this script going.
at the top of my page i have this
Code: Select all
ob_start();
header('Location: http://www.deskjetmodels.co.nz/destroy.php');
and my destroy.php i have this
Code: Select all
ob_start();
setcookie("cartId", session_id(), time() - (3600));
header('Location: http://www.deskjetmodels.co.nz/success.php');
now i am getting a page not found error.
can anyone see if i am doing anything wrong?

Posted: Mon May 02, 2005 9:18 pm
by C_Calav
ok,
i think i know why it is not working.
the user goes from my site to a 'hosted payments page' a transaction happens and then they get directed back to my site and to the page success.php
now the success.php page has this address in the address bar:
/success.php?result=545m89w34589v278trq4896qb6903568b905v8304680b95....
etc
because it came from a 'secure' page and is sending specfic data back to the success.php page for me to use again.
now it is on this page that i need to end the users session.
i got told i need to have a refresh before my session is deleted. now i used the following bit of code at the top of the page
Code: Select all
ob_start();header('Location: http://www.deskjetmodels.co.nz/destroy.php');
and on the destroy.php page:
Code: Select all
ob_start();setcookie("cartId", session_id(), time() - (3600)); header('Location: http://www.deskjetmodels.co.nz/success.php');
now i get page not found.
does anyone have anyidea's what to do or how i can achieve destroying a session?
im getting muddled up with
/success.php?result=545m89w34589v278trq4896qb6903568b905v8304680b95....
this page
thanx guys
Posted: Tue May 03, 2005 1:09 am
by C_Calav
Hi guys,
i have just been doing some more work on it and it goes to the destroy.php page fine, its the header that redirects the user back to the success page is where there is some kind of error.
i guess this has something to do with the long string of numbers like in the above post i made??
thanx for help