note 74090 added to function.session-destroy
| From: | Paper! at osu1 dot php dot net | Date: | Fri, 23 Mar 2007 21:47:35 +0000 |
| Subject: | note 74090 added to function.session-destroy | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124764@lists.php.net to get a copy of this message | ||
example1:
if no session is registered yet, (i.e: no session value is set yet ),
how to recognize this case? because it's possible that this case will be after session
Destroying!!, then below is an test to clarify session values:
<?php
session_start();
echo $_SESSION."\n<br>";
echo $_SESSION['mysession']."\n<br>"; //no output
// CASE 1: $_SESSION['session_name'] is not set yet
// TEST 1.1:
if(
NULL ==$_SESSION['mysession'] and
Array()==$_SESSION['mysession'] and
empty($_SESSION['mysession']) and
$not_defined==$_SESSION['mysession'] and
FALSE==$_SESSION['mysession'] and
Array()!==$_SESSION['mysession']
){
echo "TRUE TEST 1.1\n<br>";
}
//TEST 1.2:
if(
0==$_SESSION['mysession'] and
''==$_SESSION['mysession'] and
TRUE!=$_SESSION['mysession'] and
!is_array($_SESSION['mysession']) and
!is_bool($_SESSION['mysession']) and
!is_string($_SESSION['mysession']) and
!is_numeric($_SESSION['mysession']) and
is_null($_SESSION['mysession']) and
!isset($_SESSION['mysession'])
){
echo "TRUE TEST 1.2\n<br>";
}
//----------------------------------
//CASE 2: $_SESSION is not set yet
//TEST 2.1
if(
NULL ==$_SESSION and
Array()==$_SESSION and
empty($_SESSION) and
FALSE==$_SESSION and
$not_defined==$_SESSION and
array()!==$_SESSION['mysession']
){
echo "TRUE TEST 2.1\n<br>";
}
//TEST 2.2
if(
0!=$_SESSION and
''!=$_SESSION and
TRUE!=$_SESSION and
!is_bool($_SESSION) and
!is_string($_SESSION) and
!is_numeric($_SESSION) and
!is_null($_SESSION) and
isset($_SESSION) and
is_array($_SESSION)
){
echo "TRUE TEST 2.2\n<br>";
}
/*--------------
-> OUT PUT:
-----------
Array
TRUE TEST 1.1
TRUE TEST 1.2
TRUE TEST 2.1
TRUE TEST 2.2
-----------------*/
?>
exapmle 2:
if session is registered, and then destroyed via
$_SESSION=array();
session_destroy() ;
so, how do you know that? below is a good exmaple to know how to work with session after being
destroyed
<?php
session_start();
$_SESSION=array();
$_SESSION['mysession'] = array();
session_destroy();
echo $_SESSION."\n<br>";
echo $_SESSION['mysession']."\n<br>";
// CASE 1: $_SESSION['session_name'] after destroy_session()
// TEST 1.1:
if(
NULL ==$_SESSION['mysession'] and
Array()==$_SESSION['mysession'] and
empty($_SESSION['mysession']) and
array()===$_SESSION['mysession'] and
FALSE==$_SESSION['mysession'] and
$not_defined==$_SESSION['mysession']
){
echo "TRUE TEST 1.1\n<br>";
}
//TEST 1.2:
if(
0!=$_SESSION['mysession'] and
''!=$_SESSION['mysession'] and
TRUE!=$_SESSION['mysession'] and
is_array($_SESSION['mysession']) and
!is_bool($_SESSION['mysession']) and
!is_string($_SESSION['mysession']) and
!is_numeric($_SESSION['mysession']) and
!is_null($_SESSION['mysession']) and
isset($_SESSION['mysession'])
){
echo "TRUE TEST 1.2\n<br>";
}
//CASE 2: $_SESSION after destroy_session()
//TEST 2.1
if(
NULL !=$_SESSION and
Array()!=$_SESSION and
!empty($_SESSION) and
FALSE!=$_SESSION and
$not_defined!=$_SESSION
){
echo "TRUE TEST 2.1\n<br>";
}
//TEST 2.2
if(
0!=$_SESSION and
''!=$_SESSION and
TRUE==$_SESSION and
!is_bool($_SESSION) and
!is_string($_SESSION) and
!is_numeric($_SESSION) and
!is_null($_SESSION) and
isset($_SESSION) and
is_array($_SESSION)
){
echo "TRUE TEST 2.2\n<br>";
}
/*------------------------
-> OUT PUT:
-----------
Array
Array
TRUE TEST 1.1
TRUE TEST 1.2
TRUE TEST 2.1
TRUE TEST 2.2
--------------------------------------------------*/
?>
:)
----
Server IP: 217.13.201.10
Probable Submitter: 85.195.119.14
----
Manual Page -- http://www.php.net/manual/en/function.session-destroy.php
Edit -- https://master.php.net/note/edit/74090
Del: integrated -- https://master.php.net/note/delete/74090/integrated
Del: useless -- https://master.php.net/note/delete/74090/useless
Del: bad code -- https://master.php.net/note/delete/74090/bad+code
Del: spam -- https://master.php.net/note/delete/74090/spam
Del: non-english -- https://master.php.net/note/delete/74090/non-english
Del: in docs -- https://master.php.net/note/delete/74090/in+docs
Del: other reasons-- https://master.php.net/note/delete/74090
Reject -- https://master.php.net/note/reject/74090
Search -- https://master.php.net/manage/user-notes.php