我想知道你如何展示在线用户?一旦他们登录,我希望它显示在我的会员页面上,现在我得到了多少用户。如果用户关闭浏览器或注销它也不会显示任何在线用户,我也想要超时,这是总会员的代码......
<?
if ($_GET[user] != "") {
$check_query = mysql_query("SELECT * FROM users WHERE username='$lowerusername'");
if (mysql_num_rows($check_query) != "0") {
} else {
header("Location: /usernotfound.php");
}
}
?>
<?
$username = $_SESSION['membersusername'];
$check_query3 = mysql_query("SELECT * FROM users WHERE username='$username'");
while ($display = mysql_fetch_array($check_query3)) {
$bio = $display['bio'];
}
?>
<?
if ($_GET[user] != ""){
$check_query = mysql_query("SELECT * FROM users WHERE username='$lowerusername'");
while ($display = mysql_fetch_array($check_query)) {
$twitter = $display['twitter'];
$facebook = $display['facebook'];
$tinychat = $display['tinychat'];
$vaughnlive= $display['vaughnlive'];
$uploadbanner = $display['uploadbanner'];
$uploadbg= $display['uploadbg'];
$backgroundcolor = $display['backgroundcolor'];
$bgp = $display['bgp'];
$bgr = $display['bgr'];
$bga = $display['bga'];
$btc = $display['btc'];
$image = $display['image'];
$status1 = $display['status'];
$djname2 = ":: $djname2 Profile";
$djname3 = "$djname3";
$djname = "<strong>Name:</strong> $name";
$age = "<strong>DOB:</strong> $age1";
$email = "<strong>E-Mail:</strong> <a href='mailto:$email1'>$email1</a>";
$year = date('d/m/Y');
$totalage = $year-$age1;
}}
?>
<?
if ($_GET[user] != ""){
$check_query = mysql_query("SELECT * FROM profiles WHERE username='$lowerusername'");
while ($display = mysql_fetch_array($check_query)) {
$twitter = $display['twitter'];
$facebook = $display['facebook'];
$tinychat = $display['tinychat'];
$vaughnlive= $display['vaughnlive'];
$uploadbanner = $display['uploadbanner'];
$uploadbg= $display['uploadbg'];
$backgroundcolor = $display['backgroundcolor'];
$bgp = $display['bgp'];
$bgr = $display['bgr'];
$bga = $display['bga'];
$btc = $display['btc'];
$username = $display['username'];
$image = $display['image'];
}}
?>
<? $check_query = mysql_query("SELECT * FROM profiles WHERE username='$_SESSION[membersusername]'");
while ($display = mysql_fetch_array($check_query)) {
$image1 = $display['image'];
if ($image1 == "") {
$image1 = "profile/nophoto.gif";
} else {
$image1 = "profile/$username/$image1";
}}
?>
<?
$check_query_all = mysql_query("SELECT * FROM users WHERE hiddenauth='no' AND auth='yes' ORDER BY id DESC");
while ($display = mysql_fetch_array($check_query_all)) {
$allmembers = $display['name'];
$allusername = $display['username'];
$allbio = $display['bio'];
$allage = $display['age'];
// get more stuff above if u need
$check_query_all2 = mysql_query("SELECT * FROM profiles WHERE username='$allusername'");
while ($display = mysql_fetch_array($check_query_all2)) {
$allimage = $display['image'];
$alllocation = $display['location'];
// Check Album Photo's
$check_amount = mysql_query("SELECT * FROM users WHERE hiddenauth='no' AND auth='yes'");
$num_djs_total = mysql_num_rows($check_amount);
// CHECK IF IMAGE OR NOT
if ($allimage == "") {
$allcheckedimage = "nopic.gif"; }
// CHECK IF IMAGE OR NOT
if ($allimage != "") {
$allcheckedimage = "$allusername/$allimage"; }
// CHECK IF location OR NOT
if ($alllocation == "") {
$allcheckedlocation = "No Idea"; }
// CHECK IF location OR NOT
if ($alllocation != "") {
$allcheckedlocation = "$alllocation"; }
// CHECK IF mini bio OR NOT
if ($allbio == "") {
$allcheckedbio = "Something about your show."; }
// CHECK IF mini bio OR NOT
if ($allbio != "") {
$allcheckedbio = "$allbio"; }
$listalldjs .= "<table class='inlineTable' width='452' border='0'>
<tr>
<td width='20%'><img src='$domain/profile/$allcheckedimage' width='180' height='173'/></td>
<td width='83%'><b>Username:</b> $allusername<br /><b>Location:</b> $allcheckedlocation<br /><b>Show Description:</b><br>$allcheckedbio<div align='right'><a href='$domain/$allusername'/>View Channel</a>
</div> </td>
</tr>
</table>";
}}
?>
这是登录代码......
<?php session_start(); ?>
<? include "includes/dbconfig.php"; ?>
<? include "includes/loggedin_config.php"; ?>
<?
$lowerusername = strtolower($_POST[username]);
// MEMBERS LOGIN CHECK IF USER EXISTS :D
if ($_GET[action] == "login") {
$check_query = mysql_query("SELECT * FROM users WHERE username='$lowerusername' AND password='$_POST[password]' AND auth='yes'");
if (mysql_num_rows($check_query) != "1") {
$error = "Incorrect details! or You have not authorized your account!";
} else {
$_SESSION[ipaddress] = $_SERVER['REMOTE_ADDR'];
$_SESSION[membersusername] = $lowerusername;
header('Location: main.php');
}
}
?>
任何人都可以帮我制作一个只有在线剧本而非总会员吗?如果是这样,我需要添加到MySQL表中?
由于
答案 0 :(得分:2)
请注意
mysql_ *函数已弃用。使用 PDO 或 MySQLi
确保MySQL服务器上PHP服务器的时区 UTC 。
在MySQL用户表中添加seen
列。
当登录用户访问您网站上的任何页面时,请将当前用户的“看到”行更新为SQL函数NOW()
:
$username = $_SESSION['membersusername'];
if(isset($username)){
mysql_query("UPDATE users SET seen=NOW() WHERE username='$username'");
}
如果用户只是停留在您的页面中,请将 AJAX 请求发送到更新所见行的页面。
在要显示在线用户的页面上,循环浏览用户,检查“看到”行是否小于当前时间--20秒。
如果不到20秒,该用户就会离线。否则用户在线。 实施例
$sql=mysql_query("SELECT seen FROM users");
while($rows=mysql_fetch_array($sql)){
$seen=$rows['seen'];
if($seen < date("Y-m-d H:i:s",strtotime('-20 seconds', time()))){
echo "User Is offline";
}else{
echo "User is online";
}
}
您可以将此 20 秒设置为更多或更少的时间。
答案 1 :(得分:1)
你需要一个cron。
每10秒检查一次用户是否已登录?
step1。当用户登录时,在表字段中输入标记值“是”。
步骤2.每10秒检查一次用户是否已登录:您可以在用户注销或用户关闭选项卡时触发查询,并使用标记“no”更新完全相同的字段。
如果您使用任何Cookie,请确保正确使用Cookie。