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 7584847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:01:18+00:00 2026-05-30T19:01:18+00:00

What does session_destroy() function do? To delete all session variables in global array $_SESSION

  • 0

What does session_destroy() function do? To delete all session variables in global array $_SESSION I have to use session_unset(). To remove session from the client browser (delete session id and name) I have to unset cookies:

unset($_COOKIES[session_id()]);
unset($_COOKIES[session_name()]);

Why session_destroy() function is needed?

  • 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-05-30T19:01:20+00:00Added an answer on May 30, 2026 at 7:01 pm

    session_destroy() ends the whole session, meaning it will be removed from PHP’s session storage and can’t ever be used again. If you’d only unset the session variables and cookies, the session would still be active server-side and could potentially be recycled if some session variables are set again and the cookie with the original session ID is sent to the client again.

    To put it in another way: a session basically consists of a secret ID stored somewhere on the web server, together with session variables registered to that session. The session ID is sent to the client (usually as a cookie) so the client can be identified as ‘owner’ of the session on later requests. Assuming a session has already been created and has variables registered to it, here’s an overview of what the functions do:

    • session_start() imports all session variables belonging to the session ID that the client sent from the session registry to the $_SESSION array
    • session_unset() or calling unset() on $_SESSION variables will clear all variables registered to the current session, but it will not clear the session itself
    • Unsetting the session cookie of the client will signal to the client that the session is over, but this will not remove the session from the session registry on the server either
    • session_destroy() is the only function that will actually purge the session from the session registry, thus literally ‘destroying’ the session

    While session_destroy() will unregister all session variables, it won’t clear the $_SESSION array in the script that’s currently executing, so it’s still a good idea to unset the session variables to prevent bugs and security issues.

    On a related note, the PHP manual recommends not to use session_unset() but rather unset the keys from $_SESSION:

    If $_SESSION (or $HTTP_SESSION_VARS for PHP 4.0.6 or less) is used, use unset() to unregister a session variable, i.e. unset($_SESSION['varname']);.

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

Sidebar

Related Questions

Does session_unset() unregister all the $_SESSION vars, or do you have to manually clear
I previously used these three lines to delete a session: session_start(); session_regenerate_id(); session_destroy(); Does
Does a new SessionFactor y and Session object have to be created for each
Does ASP.NET 4.0 have any improvements as to inbuilt protection against Session Fixation attacks?
Let's say you have a aspx page that does not rely on session, but
Does Google force employees who have offers from Facebook to leave immediately?
Does the $_SESSION expire at any time point? Obviously you can call session_destroy() or
I have searched many questions regarding session_destroy and the often response from the answerers
does anybody have experience with OmniAuth & Facbeook? I just moved from using a
Our user authentication system makes use of cookies and $_SESSION variables to determine logged-in

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.