[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

session_destroy();

Posted on 2005-04-19
6
Medium Priority
?
917 Views
Last Modified: 2013-12-12
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
Comment
Question by:Princess_sana
5 Comments
 
LVL 18

Expert Comment

by:arantius
ID: 13820632
$_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
 

Author Comment

by:Princess_sana
ID: 13820687
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
 
LVL 14

Expert Comment

by:cracky
ID: 13820791
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
 
LVL 18

Accepted Solution

by:
arantius earned 2000 total points
ID: 13824387
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
 
LVL 10

Expert Comment

by:Kshitij Ahuja
ID: 15664047
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month18 days, 21 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question