Portal Home > Knowledgebase > Articles Database > PHP: When should unset be used?


PHP: When should unset be used?




Posted by MatthewT, 06-27-2008, 11:44 PM
I know it sounds like a rather basic question, but aside from unsetting sessions in logout scripts etc, in PHP when should unset fuction be used? is there a general 'rule' for when its best practice to use it? Just want to make 100% sure that under no circumstances can the value of variables used on a page be carried over from a previous loading of the page right? I know its probably a dumb question, but better to ask a dumb question than make a dumb mistake right?

Posted by Tree NC, 06-27-2008, 11:50 PM
The only variables that carry from one pageload to another are session variables and cookies. For more info on unset(), check out PHP's docs.

Posted by MatthewT, 06-28-2008, 12:14 AM
Thanks for the quick reply, its what I figured, hence the very need for session and cookie variables. Just had some odd results in testing last night. I think it may have been a very unlikely fluke considence in some random text i inputted in a form and a small error in a cleaning function. Just want't to make sure i wasn't going crazy Thanks.

Posted by greg2007, 06-28-2008, 03:21 PM
You might want to check that register_globals is turned off. It is usually by default now. And just to confirm, whenever you set a $_SESSION it will remain set until you unset it or the browser is closed (or browser data is cleared).

Posted by RN-Chris, 06-28-2008, 03:36 PM
or

Posted by Codebird, 06-28-2008, 07:06 PM
if you need to destroy all session variables you use session_destroy if you need to unset some and keep some you use the unset($_SESSION["blabla"])

Posted by MatthewT, 06-30-2008, 04:53 AM
Thanks for all the replies



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
does thsi sound good? (Views: 571)