Garbage collection for ci_sessions

This commit is contained in:
2023-06-25 12:03:06 +02:00
parent a43450556d
commit 013eb15d04
2 changed files with 77 additions and 66 deletions
+51 -40
View File
@@ -8,61 +8,72 @@
class MY_Controller extends CI_Controller { class MY_Controller extends CI_Controller {
public $authenticated; public $authenticated;
public $user; public $user;
public $version; public $version;
public function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
$this->version = '1.00.81'; $this->version = '1.00.81';
$this->load->library( 'beheer/session/RetrieveUserSession' ); $this->load->library( 'beheer/session/RetrieveUserSession' );
$this->handle(); $this->handle();
} }
private function handle() private function handle()
{ {
$this->setSecureSite(); $this->garbageCiSessions();
$this->retrieveusersession->handle(); $this->setSecureSite();
$this->user = $this->User_model->get( USERID ); $this->retrieveusersession->handle();
}
public function setSecureSite() $this->user = $this->User_model->get( USERID );
{ }
if ( getenv( 'ENVIRONMENT' ) != 'production' ) return;
if ( ! isset( $_SERVER["HTTPS"] ) || $_SERVER["HTTPS"] != "on" ) public function garbageCiSessions()
{ {
header( "Location: " . getenv( 'APP_URL' ) ); $number = random_int(0, 100);
exit; if( $number != 17 ) return;
}
}
function clean_input( $post ) $this->db->query( "DELETE FROM ci_sessions WHERE TIMESTAMPDIFF(MINUTE, FROM_UNIXTIME(timestamp), NOW()) > 60" );
{ }
$value = $this->input->input_stream( $post, TRUE );
$denulledValue = str_replace( 'null', '', $value ); public function setSecureSite()
{
if ( getenv( 'ENVIRONMENT' ) != 'production' ) return;
return $denulledValue; if ( ! isset( $_SERVER["HTTPS"] ) || $_SERVER["HTTPS"] != "on" )
} {
header( "Location: " . getenv( 'APP_URL' ) );
public function json( $data ) exit;
{ }
$this->output }
->set_content_type( 'application/json' )
->set_output( json_encode( $data ) );
}
public function unAuthorized() function clean_input( $post )
{ {
$value = $this->input->input_stream( $post, TRUE );
} $denulledValue = str_replace( 'null', '', $value );
return $denulledValue;
}
public function json( $data )
{
$this->output
->set_content_type( 'application/json' )
->set_output( json_encode( $data ) );
}
public function unAuthorized()
{
}
} }
+26 -26
View File
@@ -155,32 +155,32 @@ function setTextAreaHtml( $text )
function checkBsn( $bsn ) function checkBsn( $bsn )
{ {
if ( strlen( $bsn ) < 8 || strlen( $bsn ) > 9 ) // if ( strlen( $bsn ) < 8 || strlen( $bsn ) > 9 )
{ // {
return FALSE; // return FALSE;
} // }
else // else
{ // {
$sum = 0; // $sum = 0;
$counter = strlen( $bsn ); // $counter = strlen( $bsn );
$pos = 0; // $pos = 0;
for ( $i = $counter; $i > 0; $i -- ) // for ( $i = $counter; $i > 0; $i -- )
{ // {
if ( $i == 1 ) // if ( $i == 1 )
{ // {
$sum = $sum + intval( $bsn{$pos} ) * - 1; // $sum = $sum + intval( $bsn{$pos} ) * - 1;
} // }
else // else
{ // {
$sum = $sum + ( intval( $bsn{$pos} ) * $i ); // $sum = $sum + ( intval( $bsn{$pos} ) * $i );
} // }
$pos ++; // $pos ++;
} // }
if ( $sum % 11 != 0 ) // if ( $sum % 11 != 0 )
{ // {
return FALSE; // return FALSE;
} // }
} // }
return TRUE; return TRUE;
} }