开发者

Link to kill a connection of connected user PHP

I have a list of 'Active Users' on my page. Is it possible to create a link to immediately disconnect that user temporarily, and then perhaps regrant them access? I found it online somewhere :D

<?php
if(isset($_POST['username']) && isset($_POST['password'])){
    $_SESSION['username']=$_POST['username'];
}开发者_开发技巧

?>
             <h1>Currently Active Users</h1><br/>
             <?php 
             $d=date('c',time()-1800);
             $q=mysql_query("select username from navigation where time>'$d'");
             if(mysql_affected_rows()>0){
                 print "<ul>";
                 while($users=mysql_fetch_array($q)){
                    print "<li>{$users[0]}</li>";
                 }
                 print "</ul>";
             }
             ?>


create DB named kill with UID (user_id)

<?php
include("db.php");
$bans = mysql_query("SELECT * FROM kill WHERE uid = ".$user_id." LIMIT 1");
$ban = mysql_fetch_assoc($bans);
if ($ban)
{
    mysql_query("DELETE FROM kill WHERE id = $ban[id]");
    die("Banned");
}


HTTP is stateless, so there is no such thing as a "Connected user".

There are things you can do to manipulate the session for a specific user - but without knowing how the session management is implemented (assuming that this concept of 'Active Users' has any correlation to PHP sessions). But you've not provided any information about how the "navigation" table is populated.

Also the code you've presented here is not very well written

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜