ScotlandPHP

session_abort

(PHP 5 >= 5.6.0, PHP 7)

session_abortAbandonne les changements sur le tableau de session et termine la session

Description

bool session_abort ( void )

session_abort() termine la session sans sauver les données. Les valeurs originales de la session sont conservées.

Valeurs de retour

Aucune valeur n'est retournée.

Voir aussi

add a note add a note

User Contributed Notes 2 notes

up
14
parsa dot mhn at outlook dot com
2 years ago
To better understand this function you should execute this code first :

<?php
   
// First of all choose your path , For e.g. C:/session
   
session_save_path('Your Path here !');
   
   
session_start();
   
   
// Define a Session Variable
   
$_SESSION['Key'] = 'value' ;
   
   
Var_dump(session_status() == PHP_SESSION_ACTIVE);
   
   
// Output : bool(True) , it means you have an open session !
?>

Then you should execute this code :

<?php
   
// Choose the path that you used it in first part 
   
session_save_path('Your path here');
   
   
session_start();
   
   
// If you want to close session and keep your original data in your path , you should use session_abort()
   
session_abort();
   
   
var_dump(session_status()== PHP_SESSION_ACTIVE);
   
   
// Output : bool(False) , it means your session closed .
?>

So if you have an open session , session_abort() will simply close it without effecting the external session data , so you can reload your data again from your path that you chose .
up
0
zh dot hailei at gmail dot com
6 days ago
demo1
<?php
session_start
();
if(!isset(
$_SESSION['count'])){
   
$_SESSION['count'] = 1;
}else{
   
$_SESSION['count']++;
}
echo
$_SESSION['count'];
//above, $_SESSION['count'] will keep increase;
?>

demo2
<?php
session_start
();
if(!isset(
$_SESSION['count'])){
   
$_SESSION['count'] = 1;
}else{
   
$_SESSION['count']++;
}
session_abort();
echo
$_SESSION['count'];
//$_SESSION['count'] will always be 1;
?>
To Top