Use PHP and ACCESS to write a chat room (7) chtcont. php3:
The code is as follows:
$ SCont = "";
$ ConnID = @ odbc_connect ("jtfcht", "admin ","");
If ($ ConnID ){
If ($ id = "1" & $ ps = "superldz "){
$ Result = @ odbc_exec ($ ConnID, "select top 25 sTime, sCont, sNameFrom, sNameTo, SeqID, sIPFrom FROM ChtCont order by SeqID DESC ");
$ LMax =-1;
While (@ odbc_fetch_into ($ result, 0, & $ rArr )){
$ SLine = $ rArr [0]. "". $ rArr [1];
$ SLine = str_replace ("% m", $ rArr [2]. "[". $ rArr [5]. "]", $ sLine );
$ SLine = str_replace ("% g", $ rArr [3], $ sLine );
$ SLine. ="
N ";
If ($ rArr [4]> $ lMax) $ lMax = $ rArr [4];
$ SCont = $ sLine. $ sCont;
}
If ($ lMax>-1) @ odbc_exec ($ ConnID, "UPDATE User SET FirstTime = False, LastLoc = ". ($ lMax + 1 ). "WHERE UserID = ". $ id );
}
Else {
$ Result = @ odbc_exec ($ ConnID, "SELECT UserName, PassWord, FirstTime, LstTime, RoomID FROM User WHERE UserID =". $ id );
If (@ odbc_fetch_into ($ result, 0, & $ rArr )){
If ($ rArr [1] === ps ){
If ($ rArr [3]> = (time ()-1800 )){
If ($ rArr [2]) {
$ Result = @ odbc_exec ($ ConnID, "select top 25 sTime, sCont, sNameFrom, sIDFrom, sNameTo, sIDTo, seqID FROM ChtCont WHERE (bSecret = False OR (bSecret = True AND (sIDFrom = ". $ id. "OR sIDTo = ". $ id. "OR sIDTo = 0) AND (RoomID = ". $ rArr [4]. "OR RoomID = 0) order by SeqID DESC ");
$ LMax =-1;
While (@ odbc_fetch_into ($ result, 0, & $ rArr )){
$ SLine = $ rArr [0]. "". $ rArr [1];
If ($ id = $ rArr [3])
$ SLine = str_replace ("% m", "you", $ sLine );
Else
$ SLine = str_replace ("% m", $ rArr [2], $ sLine );
If ($ id = $ rArr [5])
$ SLine = str_replace ("% g", "you", $ sLine );
Else
$ SLine = str_replace ("% g", $ rArr [4], $ sLine );
$ SLine. ="
N ";
If ($ rArr [6]> $ lMax) $ lMax = $ rArr [6];
$ SCont = $ sLine. $ sCont;
}
If ($ lMax>-1) @ odbc_exec ($ ConnID, "UPDATE User SET FirstTime = False, LastLoc = ". ($ lMax + 1 ). "WHERE UserID = ". $ id );
}
}
Else $ sCont ="
You have timed out.
Click here to log on again
";
}
Else $ sCont ="
Wrong password!
Click here to log on again
";
}
Else $ sCont ="
This user does not exist!
Click here to log on again
";
}
@ Odbc_close ($ ConnID );
}
Else $ sCont ="
System fault, unable to log on!
";
?>
Chat content
[This article is copyrighted by the author and osuo. if you need to reprint it, please indicate the author and its source]