• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 923
  • Last Modified:

session_destroy();

i started a session with :
session_start();
which is palced in my header.html
i knw this is wrkin
but how do i delete this session?
i have a checkout page
this checkout page also includes the header which means the session is intialized
at the end of my checkout source code i included:

<?php
// Unset all of the session variables.
session_unset();
// Finally, destroy the session.
session_destroy();
?>
the checkout page runs fine
and i get no error msgs
however when i go bck to my shoping cart why r the items stil in the cart?

plz can someone help
thnks
0
Princess_sana
Asked:
Princess_sana
1 Solution
 
arantiusCommented:
$_SESSION=new array();

example from the PHP manual:

<?php

// Initialize the session.
// If you are using session_name("something"), don't forget it now!
session_start();
// Unset all of the session variables.
$_SESSION = array();
// Finally, destroy the session.
session_destroy();

?>
0
 
Princess_sanaAuthor Commented:
i used:
<?php

// Initialize the session.
// If you are using session_name("something"), don't forget it now!
session_start();
// Unset all of the session variables.
$_SESSION = array();
// Finally, destroy the session.
session_destroy();

?>

and i got the folwoing msg:

The order has been placed.


Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/ugrad/ma101ss/public_html/giftsgalore/includes/header.html:10) in /home/ugrad/ma101ss/public_html/giftsgalore/checkout.php on line 110

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/ugrad/ma101ss/public_html/giftsgalore/includes/header.html:10) in /home/ugrad/ma101ss/public_html/giftsgalore/checkout.php on line 110


so i removed the start_session()and used:

// Unset all of the session variables.
$_SESSION = array();

// Finally, destroy the session.
session_destroy();

and got the msg:

Warning: session_destroy(): Trying to destroy uninitialized session in /home/ugrad/ma101ss/public_html/giftsgalore/checkout.php on line 114

what am i doign wrong?
and in the code:
<?php

// Initialize the session.
// If you are using session_name("something"), don't forget it now!
session_start();
// Unset all of the session variables.
$_SESSION = array();
// Finally, destroy the session.
session_destroy();

?>
wat does" // If you are using session_name("something"), don't forget it now! " mean?
0
 
crackyCommented:
You need to place the session initialisation before any echo or html output on your page to avoid the headers sent error. Since you aren't initialising the session, you can't  destroy it.

> what does" // If you are using session_name("something"), don't forget it now! " mean?

Just means don't forget the name of session variables from page to page ;)
0
 
arantiusCommented:
No, actually, it means if you were calling session_name() elsewhere when using the session, don't forget to do it now or things won't work the way you expect.

http://us4.php.net/manual/en/function.session-name.php
0
 
Kshitij AhujaTechnology DeveloperCommented:
No comment has been added to this question in more than 21 days,so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:
[Accept arantius's comment]

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

Kshitij Ahuja
EE Cleanup Volunteer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now