[Share] Magic Mirror Online: An online random chat website source code program uses PHP + MySQL, jQuery to implement Ajax, DIV + CSS for page layout, and a client program written in VB. Original Demo address: http://ask.n9sky.com/MagicMirror/ (now can not access [share] "Magic Mirror Online" an online random chat site source code
The program uses PHP + MySQL, jQuery to implement Ajax, DIV + CSS for page layout, and a client program written in VB.
Original Demo address: http://ask.n9sky.com/MagicMirror/ (not accessible now)
Now some code is pasted:
The main operations of server. php are handled in this file.
PHP code
$ Do = @ $ _ GET ['do '];
If (''= $ do)
{
Exit ('missing action ');
}
Require 'config. php ';
Require 'dll. php ';
Session_start ();
// Check the session
If (''= $ _ SESSION ['Sid ']) exit ('logon timeout. Please close and try again! ');
Switch ($ do)
{
Case 'init ':
// Check user & update
Dll: import ('mysql ');
$ Db = new mysql ();
$ Db-> connect ($ dbs ['server'], $ dbs ['user'], $ dbs ['password']);
$ Db-> database ($ dbs ['database']);
// Update
$ Rs = $ db-> update (DBPrefix. 'user', 'Sid = "'. $ _ SESSION ['Sid'].'" ');
$ Rs-> set ('Client _ ','');
$ Rs-> set ('role', RoleOnline );
$ Rs-> set ('last _ access_time ', time ());
$ Rs-> setfunc ('login _ count', 'login _ count + 1 ');
$ Rs-> set ('last _ login_time ', time ());
$ Ip = $ _ SERVER ['remote _ ADDR '];
$ Ipx = explode ('.', $ ip );
$ Iplong =
$ Ipx [0] * 16777216 +
$ Ipx [1] * 65536 +
$ Ipx [2] * 256 +
$ Ipx [3];
$ Rs-> set ('last _ login_ip ', $ iplong );
If (! $ Rs-> update ())
{
// Add new
$ Rs = $ db-> insert (DBPrefix. 'user ');
$ Rs-> set ('Sid ', $ _ SESSION ['Sid']);
$ Rs-> set ('Client _ ','');
$ Rs-> set ('role', RoleOnline );
$ Rs-> set ('last _ access_time ', time ());
$ Rs-> set ('login _ count', 1 );
$ Rs-> set ('last _ login_time ', time ());
$ Rs-> set ('last _ login_ip ', $ iplong );
$ Rs-> insert ();
}
$ Db-> close ();
// Display init page
Display('init.html ');
Break;
Case 'status ':
Dll: import ('mysql ');
// Access $ dbs
Global $ dbs;
$ Db = new mysql ();
$ Db-> connect ($ dbs ['server'], $ dbs ['user'], $ dbs ['password']);
$ Db-> database ($ dbs ['database']);
// Update access
Update_access ($ db );
// Import mysql. class
Display('server.status.html ');
$ Db-> close ();
Break;
Case 'work ':
$ Mode = $ _ GET ['mode'];
// Update work mode
Dll: import ('mysql ');
$ Db = new mysql ();
$ Db-> connect ($ dbs ['server'], $ dbs ['user'], $ dbs ['password']);
$ Db-> database ($ dbs ['database']);
// Update
$ Rs = $ db-> update (DBPrefix. 'user', 'Sid = "'. $ _ SESSION ['Sid'].'" ');
Switch ($ mode)
{
Case 'ancer ':
$ Rs-> set ('role', RoleAnswer );
Break;
Case 'asker ':
$ Rs-> set ('role', RoleAsker );
Break;
Case 'chater ':
$ Rs-> set ('role', RoleChater );
Break;
Case 'offline ':
$ Rs-> set ('role', RoleOffline );
$ Rs-> set ('Client _ ','');
// Delete input status cache
@ Unlink (dirname ('.'). '/cache/'. $ _ SESSION ['Sid '].'. input. status ');
// Clear session
Unset ($ _ SESSION );
Break;
}
$ Rs-> set ('last _ access_time ', time ());
$ Rs-> update ();
$ Db-> close ();
// Display mode page
If ($ mode! = 'Offline ')
{