mercredi 29 août 2018

How to kick(disconnect) specific user (client) in mysql using laravel query?

I want to kick(disconnect) specific user(client) in mysql using Laravel.

What I tried:

I make a function in Login Controller to store connection id, ip and dateTime.

public function authenticated(Request $request, $user)
{   

    $conn = DB::select("show full processlist");

    foreach($conn as $con){
        $user->connID = $con->Id;
        $user->connDate = Carbon::now();
        $user->last_login_ip = $con->Host;
        $user->update();
        }
}   

and i create a button and make some Ajax to trigger the button and pass the user id and connection id in controller.

In my controller here is my code.

Public function closeConnection(Request $request, $id){

    $userCon = $request->conID;

    $user = DB::table('users')
                ->where('id', $id)
                ->update([
                        'connID' => null,
                        'last_login_ip' => null,
                        'connDate' => null,
                         ]);


    //return $conn;
    $conn =  DB::select("SELECT concat('KILL ',$userCon,';')");
}

the problem is, connection_id will be change dynamically if the user visit other page or doing something in web, and when i click the close button there's an error prompted "Thread not found or sometimes there's no error but the user is still connected.

What should i want to do?

I want to disconnect(kick) specific user(client) when i clicked the button.

Hope someone have an idea.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2PjYvL8
via IFTTT

Aucun commentaire:

Enregistrer un commentaire