Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7728307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:41:04+00:00 2026-06-01T05:41:04+00:00

session_start(); $_SESSION[‘user’] = 789456; $_SESSION[‘name’] = dummy; $_SESSION[‘id’] = 123; print_r($_SESSION); session_destroy(); echo Session

  • 0
session_start();
$_SESSION['user'] = "789456";
$_SESSION['name'] = "dummy";
$_SESSION['id'] = "123";
print_r($_SESSION);
session_destroy();
echo "Session End";
print_r($_SESSION);

My output is:

Array ( [user] => 789456 [name] => dummy [id] => 123)
Session End :Array ( [user] => 789456 [name] => dummy [id] => 123) 

Shouldn’t the output just be:

Array ( [user] => 789456 [name] => dummy [id] => 123)

If I use session_unset() before session_destroy() then I get the result I expect. Is it always necessary to use session_unset() before session_destroy()?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T05:41:05+00:00Added an answer on June 1, 2026 at 5:41 am

    From the documentation:

    session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie. To use the session variables again, session_start() has to be called.

    In order to kill the session altogether, like to log the user out, the session id must also be unset. If a cookie is used to propagate the session id (default behavior), then the session cookie must be deleted. setcookie() may be used for that.

    The easiest way would be: $_SESSION = array(); after calling session_destroy();.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<?php session_start(); // store session data $_SESSION['count']=0; ?> <html><head></head> <body> <?php include (getElement.php); echo
I get Session object destruction failed when I use session_destroy(). session_start(); if(isset($_SESSION['user_id'])){ $_SESSION=array(); if(isset($_COOKIE[session_name()])){
How can foreach loop affect session variable? session_start(); $_SESSION[test] = Session content; echo $_SESSION[test].'<br
index.php session_start(); if(!isset($_GET['n'])) { $_SESSION['foo'] = bar; header(Location: /index.php?n=D); } echo FOO: .$_SESSION['foo']; This
session_start(); //login page if(mysql_num_rows($result) != '0'){ // If match. session_register(username); // Craete session username.
During Session Start, one has access to the Request object. How about Session End,
I get this: Warning: session_start(): Cannot send session cookie - headers already sent by
If I write the following code: session_start(); $_SESSION['user_id']='daniel'; the variable stays fine as long
I have a header.html which start with session_start();. Then the following code, $_SESSION['cart'][$sw_id] is
Getting the following error when trying to start a session: Warning: session_start() [function.session-start]: Node

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.