Pages

Monday 25 June 2012

PHP (Destroying Session)

Destroying a PHP Session:
A PHP session can be destroyed  by session_destroy() function. This function does not need any argument and a single call can destroy all the session variables. If we have a single session we can solve purpose by using unset() function.
Let us see now how it works.
/*
below we see counter which is our previously created counter.
but if we don't know the name or we want to destroy multiple sessions we use destroy function
*/
<?php
unset($_SESSION['counter']);
?>
*******************************
<?php
session_destroy();
?>
*******************************
More On Sessions:-
We will now learn turning sessions automatically.we just need to edit one file for this purpose.

Turning on Auto Session:
In this case we have no need to call start_session() function to start a session when a user visits our site if you set session.auto_start variable to 1 in php.ini file and we can find this file in the htdocs folder.

Sessions without cookies:

There may be a case when a user does not allow to store cookies on the machine. So there is another method to send session ID to the browser.

Alternatively, you can use the constant SID which is defined if the session started. If the client did not send an appropriate session cookie, it has the form session_name=session_id. Otherwise, it expands to an empty string. Thus, one can embed it unconditionally into URLs.

The following example demonstrates how to register a variable, and how to link correctly to another page using SID.

No comments:

Post a Comment