/    Sign up×
Community /Pin to ProfileBookmark

how to destroy individual session variables

Hi,
I know how to destroy a complete session-session_destroy();

but how do you destroy individual session variables as I want to keep some of the variables in a session?
thanks

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@YoNDec 03.2003 — what if you [URL=http://us3.php.net/manual/en/function.unset.php]unset()[/URL] it?

HTH
Copy linkTweet thisAlerts:
@andymncDec 03.2003 — exact, you can simply use:

unset ($_SESSION["yoursessionvariable"]);
Copy linkTweet thisAlerts:
@mg8Dec 04.2003 — I like to use unregister()
Copy linkTweet thisAlerts:
@pyroDec 04.2003 — If you use that method, you'd best be aware that it "does not unset the corresponding global variable for name, it only prevents the variable from being saved as part of the session."

http://us3.php.net/manual/en/function.session-unregister.php
Copy linkTweet thisAlerts:
@damon2003authorDec 16.2003 — Hi,

I am having trouble unregistering session variables.

I am attempting to unregister specific variables.

I get to a page, and us this:

I have tried this first, but it destroys all session variables

session_unset($_SESSION['textfieldFirstNameCustomerExisting']);

Next I tried this, but it doesnt seem to work at all

unset($_SESSION['textfieldFirstNameCustomerExisting']);

I am using $_SESSION

so , as I understand it session_unregister() does not work here

ani ideas here,

thanks
Copy linkTweet thisAlerts:
@pyroDec 16.2003 — Are you remembering to run session_start() first? This should work fine:

[code=php]<?php
session_start();
unset($_SESSION['session_name']);
?>[/code]
Copy linkTweet thisAlerts:
@damon2003authorDec 16.2003 — yes,

I have session_start() at the top of all my pages,

I then do some stuff with the session, and then right at the end call the unset().

If I replace this with session_unset() then this destroys all variables
Copy linkTweet thisAlerts:
@damon2003authorDec 16.2003 — Hi,

I got it working,

this works

session_unregister('textfieldFirstNameCustomerExisting');

when global variabled is turned on
×

Success!

Help @damon2003 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...