怎么才能准确的判断用户是否在线呢?下面小编就来给大家分享一个实例。
解决了昨天的问题:表结果变了一下,如下:
CREATE TABLE TB_User ( --用户表
N_UserId Number(5) NOT NULL, --用户ID
V_NickName VARCHAR2(10) NOT NULL, --昵 称
V_PWD VARCHAR2(10) NOT NULL, --密 码
V_TrueName VARCHAR2(20), --姓 名
Primary Key (N_UserId)
)
CREATE TABLE TB_OnlineUser ( --在线用户
N_OnlineUserId Number(5) NOT NULL, --在线用户ID
D_LoginTime Number (16), --登陆时间以秒计
N_OnlineID Number(5), --与onlineusercount相关联。
Primary Key (N_OnlineID)
)
/
CREATE TABLE TB_OnlineUserCount ( --在线用户统计表
N_OnlineID Number(5) NOT NULL, --系统ID号
N_OnlineUserId Number(5) NOT NULL, --在线用户ID
D_LoginDate Date , --登陆日期
D_LoginTime Number (16) , --登陆时间以秒计
D_OverDate Date , --结束日期
D_OverTime Number (16) , --结束时间
Primary Key (N_OnlineID)
)
/
/*---LoginselectNew.php---该程序是登陆检查程序----*/
<?
session_start();/*思路:首先用户登陆,判断是否有该用户,判断是否密码通过,否则返回参数进行特殊处理。(登陆不成功)
登陆成功后,如果该用户不在线(一般不在线,特殊情况如果他用另一台机器打开浏览器重新再登陆,那么他有可能在线),
先进行session变量注册,取得相应条件向1.统计表与2.在线表中插数据。进入到登陆页。
如果用户在线:先取得在线用户的系统ID,因为在备份该用户离开时有用。接着删除该在线用户.接着进行该用户离开时间的备份.
*/
本支付接口的特点,主要是用xml文件来记录订单详情和支付详情。代码比较简单,只要将里面的商户号、商户key换成你自己的,将回调url换成你的网站,就可以使用了。通过这个实例也可以很好的了解一般在线支付接口的基本工作原理。其中的pay.config文件记录的是支付详情,order.config是订单详情
0
session_register("objsNickName");
require('oracle8conn.php');
$name=trim($name);
$pwd=trim($pwd);
ob_start(); //缓冲输出
$stmtNick = OCIParse($conn,"select count(*) countnickname from tb_user where v_nickname='$name'");
OCIExecute($stmtNick);
while(OCIFetchInto($stmtNick,&$arrN)){
if ($arrN[0]==0){
Header("Location:Logintest.php?Msg=1");
}else{
//用户名通过
unset($arrNickName); //撤消临时数组
$stmtPwd = OCIParse($conn,"select count(*) countpwd from tb_user where v_pwd='$pwd' and v_nickname='$name'");
OCIExecute($stmtPwd);
while(OCIFetchInto($stmtPwd,&$arrP,OCI_NUM)){
if ($arrP[0]==0){
Header("Location:Logintest.php?Msg=2");
}else{//密码通过
//取出用户的ID号
$stmtUid = OCIParse($conn,"select n_userID from tb_user where v_nickname='$name'");
OCIExecute($stmtUid);
while(OCIFetchInto($stmtUid,&$arrU,OCI_NUM)){
$intOnlineUserID=$arrU[0];
}//while_Over
//如果该用户通过另一个浏览器重复登陆,解决如下
$stmOnlineFlag=OCIParse($conn,"select count(*) from tb_onlineuser where N_ONLINEUSERID='$intOnlineUserID'");
OCIExecute($stmOnlineFlag);
while(OCIFetchInto($stmOnlineFlag,&$arronlineFlag,OCI_NUM)){
if ($arronlineFlag[0]!=0){ //表示已经在线
//先取到在线用户关联系统ID
$stmtSysID= OCIParse($conn,"select N_ONLINEID from tb_onlineuser where N_ONLINEUSERID='$intOnlineUserID'");
OCIExecute($stmtSysID);
while(OCIFetchInto($stmtSysID,&$arrSysID,OCI_NUM)){
$SysID=$arrSysID[0];
}//while_Over //找完后踢出该用户
$stmt = OCIParse($conn, "delete from tb_onlineuser where N_ONLINEUSERID='$intOnlineUserID'");
OCIExecute($stmt);
print "删除成功"; //最后作记录备份
$tmpTime=time(); //结束时间
$DatLoginDate = date( "Y-m-d");//结束日期
$DatLoginDate = "to_date('".$DatLoginDate."','YY/MM/DD')";
$stmtUserCount = OCIParse($conn, "update tb_onlineusercount set D_OverDate=$DatLoginDate ,D_OverTime=$tmpTime where N_OnlineID='$SysID'");//条件是相关联的系统ID
OCIExecute($stmtUserCount);
print "添加成功到统计表中。";
}//endif //不在线正常注册
$objsNickName=$name; //注册Session变量
unset($arrPwd); //撤消临时数组
srand((double)microtime()*1000000000);
$intOnlineID = rand(); //取一个系统ID号
$DatLoginDate = date( "Y-m-d"); //取得系统日期存入到Online表中去。
$DatLogintime = time(); //取系统时间
$DatLoginDate = "to_date('".$DatLoginDate."','YY/MM/DD')";
$stmt = OCIParse($conn, "insert into tb_onlineuser (N_OnlineUserId,D_LoginTime,N_OnlineID) values ($intOnlineUserID,$DatLogintime,$intOnlineID)");
OCIExecute($stmt);
$stmtC = OCIParse($conn, "insert into TB_OnlineUserCount (N_OnlineID,N_OnlineUserId,D_LoginDate,D_LoginTime) values ($intOnlineID,$intOnlineUserID,$DatLoginDate,$DatLogintime)");
OCIExecute($stmtC);
Header("Location:index.php"); //成功登陆!
}//whileOVER
}//end if
}//while_Over
}//end if
}//while_Over
?>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号