473,569 Members | 2,438 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

best method for unsetting a whole session

sg
Hi,

I use sessions on my site and i have an admin page where I want to be able
to unset all session variables and destroy the session.

for the moment I do :
<?
session_unset() ;
session_destroy ();
?>

This works perfectly fine for me.

BUT (yes this post has a point)

I just saw in the PHP Manual (for 'session_unset( )')
"Note: If $_SESSION (or $HTTP_SESSION_V ARS for PHP 4.0.6 or less) is used,
use unset() to unregister session variable. i.e. $_SESSION = array();"

As a matter of fact I am using the $_SESSION superglobal to manipulate my
session variables. So I think this applies to me but I don't really
understand how I should unset my session variables. And the unset() manual
page doesn't really help me either.

Can somebody clear that up for me?

Sebastien
Jul 17 '05 #1
1 4086
"sg" <sg******@frees urf.fr> wrote in message news:<bn******* ***@news-reader1.wanadoo .fr>...
Hi,

I use sessions on my site and i have an admin page where I want to be able
to unset all session variables and destroy the session.

for the moment I do :
<?
session_unset() ;
session_destroy ();
?>

This works perfectly fine for me.

BUT (yes this post has a point)

I just saw in the PHP Manual (for 'session_unset( )')
"Note: If $_SESSION (or $HTTP_SESSION_V ARS for PHP 4.0.6 or less) is used,
use unset() to unregister session variable. i.e. $_SESSION = array();"

As a matter of fact I am using the $_SESSION superglobal to manipulate my
session variables. So I think this applies to me but I don't really
understand how I should unset my session variables. And the unset() manual
page doesn't really help me either.


If you use $_SESSION superglobal,
use $_SESSION = array(); to unset the whole session array
use unset($_SESSION['foo']) to unset foo of session array.

But, don't use unset($_SESSION ) to unset the whole session array.

So, for in your case, use
$_SESSION = array(); //instead of session_unset() ;
session_destroy (); //destroy

---
"He who created the god was a fool; he who spreads his name is a
scoundrel and he who worships him is a barbarian."---Periyar, Famous
Tamil Rationalist
Email: rrjanbiah-at-Y!com
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4409
by: Sylvian Stone | last post by:
Hi there - I'm experiencing a very frustrating problem with an application that submits POST info to a session control file which then echo's it back to the controls if the page is returned to. This works fine, except for check boxes - once it is checked, if I then then return and uncheck it, then again return to the page later on, the...
1
5465
by: Pete | last post by:
I have some session variables which get set on page one of my site. I can set an unset these by passing through a parameter in some URL's. When the user goes to the second page some checkboxes are checked if their corresponding session variable is set and has a value of "true". The problem I have is that if the user unchecks a checkbox...
35
2611
by: Swartz | last post by:
Hi all. I'm working here on a small project of mine. I'm not new to programming, but I'm new to PHP. You have to understand that I'm coming from C++, OOP world, so my code might seems a little too "object"-ified. Anyways, I've created a wrapper class for MySQL connectivity. It's barebones for now, no error checking or anything. So now I'm...
8
5827
by: TS | last post by:
Im in a web page and call an asynchronous method in business class. the call back method is in the web page. When page processes, it runs thru code begins invoking the method then the page unloads. When the callback method is raised, only the method in the web page is run and the page never refreshes, it seems it all happens on the server...
1
1213
by: Kevin Frey | last post by:
I've been spending considerable time thinking about the various implications that come into play when building a production-quality web application and this has prompted me to ask whether there are any best practices guidelines on achieving this. Particular questions I have are: 1. Session management using non-persistent cookies (for Session...
17
1713
by: Shelly | last post by:
I have the following for a test of the submit button being pressed: if (isset($_POST)) { This works fine and I have been doing this for a long time. Here is the question: If I do a submit and have it come back to the same page, all is fine. If I now click the browser refresh button, I get another submittal. How do I "unset" the...
11
3018
by: john_c | last post by:
I'd like to store information for roles in Session variables. RoleA has a specific set of values, RoleB has a specific set and so one. When I access values for RoleA, it looks like this: Session = "30" Session = "1000" Session = "5" Session = "10" and similar for the other roles. Those values are initially loaded
2
4194
by: gsherp | last post by:
How do I unset PHP_AUTH_USER and PHP_AUTH_PW? I am trying to create a logout script and I am encountering a problem where when go to relogin, I am already logged in. In my logout script, I started a session, unset(session), and then destroy_session(). But, everytime I go back to the login link, It does not give me the window popup for the...
9
1698
by: Yehia A.Salam | last post by:
Hello, I am building an ASP.net website that connects to an XML database, and was wondering which is the best way to create the connection if I need frequent access to the database, I have one of the three options: 1. Use one instance of XmlDocument thought the whole Application by initializing the class in Global.asax in the...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7679
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.