public function logins($parse = true)
    {
        $result = trim(shell_exec('last'));

        if ($parse) {
            $lines = explode(PHP_EOL, $result);

            // detect end by empty line space
            $end = 0;
            foreach ($lines as $no => $line) {
                if (trim($line) == '') {
                    $end = $no;
                    break;
                }
            }
            // filter out end lines
            foreach (range($end, count($lines)) as $key) {
                unset($lines[$key]);
            }

            // define columns
            $columns = [
                'User',
                'Terminal',
                'Display',
                'Day',
                'Month',
                'Day Date',
                'Day Time',
                '-',
                'Disconnected',
                'Duration',
            ];

            // generic match rows for columns and set into return
            $result = [];
            foreach ($lines as $row => $line) {
                $column = array_values(array_filter(explode(' ', $line), 'strlen'));
                foreach ($columns as $col => $key) {
                    $result[$row][$key] = @$column[$col];
                }
            }

            // fix
            $fix = [];
            foreach ($result as $key => $row) {
                if ($row['User'] == 'reboot') {
                    $fix[] = [
                        'User' => 'Reboot',
                        'Terminal' => '',
                        'Date' => '',
                        'Disconnected' => '',
                        'Duration' => '',
                    ];
                } else {
                    if ($row['Duration'] == 'no') {
                        $row['Duration'] = '';
                    }
                    if ($row['Disconnected'] == '-') {
                        $row['Disconnected'] = '';
                    }

                    $fix[] = [
                        'User' => $row['User'],
                        'Terminal' => $row['Terminal'],
                        'Display' => $row['Display'],
                        'Date' => $row['Day'].' '.$row['Month'].' '.$row['Day Date'].' '.$row['Day Time'],
                        'Disconnected' => $row['Disconnected'],
                        'Duration' => trim($row['Duration'], '()'),
                    ];
                }
            }
            $result = $fix;
        }
        
        return $result;
    }
public function logins($parse = true)
    {
        $result = trim(shell_exec('last'));

        if ($parse) {
            $lines = explode(PHP_EOL, $result);

            // detect end by empty line space
            $end = 0;
            foreach ($lines as $no => $line) {
                if (trim($line) == '') {
                    $end = $no;
                    break;
                }
            }
            // filter out end lines
            foreach (range($end, count($lines)) as $key) {
                unset($lines[$key]);
            }

            // define columns
            $columns = [
                'User',
                'Terminal',
                'Display',
                'Day',
                'Month',
                'Day Date',
                'Day Time',
                '-',
                'Disconnected',
                'Duration',
            ];

            // generic match rows for columns and set into return
            $result = [];
            foreach ($lines as $row => $line) {
                $column = array_values(array_filter(explode(' ', $line), 'strlen'));
                foreach ($columns as $col => $key) {
                    $result[$row][$key] = @$column[$col];
                }
            }

            // fix
            $fix = [];
            foreach ($result as $key => $row) {
                if ($row['User'] == 'reboot') {
                    $fix[] = [
                        'User' => 'Reboot',
                        'Terminal' => '',
                        'Date' => '',
                        'Disconnected' => '',
                        'Duration' => '',
                    ];
                } else {
                    if ($row['Duration'] == 'no') {
                        $row['Duration'] = '';
                    }
                    if ($row['Disconnected'] == '-') {
                        $row['Disconnected'] = '';
                    }

                    $fix[] = [
                        'User' => $row['User'],
                        'Terminal' => $row['Terminal'],
                        'Display' => $row['Display'],
                        'Date' => $row['Day'].' '.$row['Month'].' '.$row['Day Date'].' '.$row['Day Time'],
                        'Disconnected' => $row['Disconnected'],
                        'Duration' => trim($row['Duration'], '()'),
                    ];
                }
            }
            $result = $fix;
        }
        
        return $result;
    }
public function logins ( $ parse = true ) { $ result = trim ( shell_exec ( 'last' ) ) ; if ( $ parse ) { $ lines = explode ( PHP_EOL , $ result ) ; // detect end by empty line space $ end = 0 ; foreach ( $ lines as $ no => $ line ) { if ( trim ( $ line ) == '' ) { $ end = $ no ; break ; } } // filter out end lines foreach ( range ( $ end , count ( $ lines ) ) as $ key ) { unset ( $ lines [ $ key ] ) ; } // define columns $ columns = [ 'User' , 'Terminal' , 'Display' , 'Day' , 'Month' , 'Day Date' , 'Day Time' , '-' , 'Disconnected' , 'Duration' , ] ; // generic match rows for columns and set into return $ result = [ ] ; foreach ( $ lines as $ row => $ line ) { $ column = array_values ( array_filter ( explode ( ' ' , $ line ) , 'strlen' ) ) ; foreach ( $ columns as $ col => $ key ) { $ result [ $ row ] [ $ key ] = @ $ column [ $ col ] ; } } // fix $ fix = [ ] ; foreach ( $ result as $ key => $ row ) { if ( $ row [ 'User' ] == 'reboot' ) { $ fix [ ] = [ 'User' => 'Reboot' , 'Terminal' => '' , 'Date' => '' , 'Disconnected' => '' , 'Duration' => '' , ] ; } else { if ( $ row [ 'Duration' ] == 'no' ) { $ row [ 'Duration' ] = '' ; } if ( $ row [ 'Disconnected' ] == '-' ) { $ row [ 'Disconnected' ] = '' ; } $ fix [ ] = [ 'User' => $ row [ 'User' ] , 'Terminal' => $ row [ 'Terminal' ] , 'Display' => $ row [ 'Display' ] , 'Date' => $ row [ 'Day' ] . ' ' . $ row [ 'Month' ] . ' ' . $ row [ 'Day Date' ] . ' ' . $ row [ 'Day Time' ] , 'Disconnected' => $ row [ 'Disconnected' ] , 'Duration' => trim ( $ row [ 'Duration' ] , '()' ) , ] ; } } $ result = $ fix ; } return $ result ; }
Get system last logins

@return string
Get system last logins