| Server IP : 61.19.30.66 / Your IP : 216.73.216.59 Web Server : Apache/2.2.22 (Ubuntu) System : Linux klw 3.11.0-15-generic #25~precise1-Ubuntu SMP Thu Jan 30 17:39:31 UTC 2014 x86_64 User : www-data ( 33) PHP Version : 5.3.10-1ubuntu3.48 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : ON | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /var/www/gpa/chat/ |
Upload File : |
<?
header("Expires: Sat, 1 Jan 2005 00:00:00 GMT");
header("Last-Modified: ".gmdate( "D, d M Y H:i:s")."GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("content-type: application/x-javascript; charset=tis-620");
$myuser=$_GET["user"]; //user
$myid=$_GET["id"]; //id
$myroom=$_GET["room"]; //ห้อง
$mytime=$_GET["time"];
$mydata=$_GET["data"];
include("config.php"); //ค่า settings
$timedat="$data$myroom.time.php"; //ไฟล์บันทึกเวลา cache usertime|contenttime
$contentdat="$data$myroom.dat.php"; //ไฟล์ข้อมูล sender|id|reciver|event|content
$usersfile="$data$myroom.user.php"; //ไฟล์บันทึกรายชื่อ user ในห้อง user|ip|id|time
$fr=file($timedat); //อ่านเวลา
$usertime=(int)$fr[0];
$contenttime=(int)$fr[1];
$fr=file($usersfile); //อ่านรายชื่อ user
$useronline_list=array(); //แอเรย์เก็บ user ที่กำลัง online
$user_list=array(); //แอเรยเก็บข้อมูลของ user
$curruser=strtolower($myuser); //แปลงเป็นตัวพิมพ์เล็ก เพื่อการตรวจสอบ
$currtime=time(); //เวลาตอนนี้
$validtime=($currtime-$gap); //กำหนดเวลาหมดของ user
$userexists=false; //กำหนดให้ยังไม่มี user นี้
$datachange="";
$id=0;
$myip=$_SERVER["REMOTE_ADDR"]; //IP ของ user
$mytime=(int)$mytime;
$mydata=(int)$mydata;
//ตรวจสอบรายการ useronline
for ($i=0; $i<count($fr); $i++) {
$datas=explode("|", $fr[$i]);
$iuser=$datas[0];
$iip=$datas[1];
$iid=(int)$datas[2];
$itime=(int)$datas[3];
if ($iuser==$myuser) { //เป็น user นี้ที่เรียกมาและมีรายชื่ออยู่แล้ว
$user_list[]="$myuser|$myip|$iid|$currtime"; //เพิ่มลงในรายการ users
$useronline_list[]="$myuser|$iid"; //เพิ่มลงในรายการ useronline
$userexists=true; //บอกว่ามี user นี้อยู่แล้ว
} else if ($validtime<=$itime) { //เป็น user อื่นและยังอยู่ในเวลาที่กำหนด
$user_list[]="$datas[0]|$iip|$iid|$itime"; //เพิ่มลงในรายการ users
$useronline_list[]="$datas[0]|$iid"; //เพิ่มลงในรายการ useronline
if ($id==$iid) $id++; //ตรวจสอบ id
if ($id==$colorcount) $id=0;
} else { //user อื่น ที่หมดเวลาแล้ว
$datachange="$datas[0]".chr(4)."$iid".chr(4).chr(4)."2".chr(4).chr(4)."$mdate $mtime\n"; //ข้อมูลสำหรับการ logout
$id=$iid;
}
}
if ($userexists==false) { //ยังไม่เคยมี user นี้
$datachange=$myuser.chr(4).$id.chr(4).chr(4)."1".chr(4).chr(4)."$mdate $mtime\n"; //ข้อมูลสำหรับการ login
$user_list[]="$myuser|$myip|$id|$currtime"; //เพิ่มลงในรายการ users
$useronline_list[]="$myuser|$id"; //เพิ่มลงในรายการ useronline
}
$f=fopen($usersfile, "w"); //บันทึกรายการ useronline
fputs($f, implode("\n", $user_list));
fclose($f);
//จบตรวจสอบรายการ useronline
if ($datachange!="") { //มีการเปลี่ยนแปลงรายการ user บันทึกเวลาใหม่
$f=fopen($contentdat, "a"); //บันทึก message
fputs($f, $datachange);
fclose($f);
$usertime++; //คำนวณเวลาใหม่
if ($usertime>99) $usertime=1;
$contenttime++;
if ($contenttime>99) $contenttime=1;
$f=fopen($timedat, "w"); //บันทึกเวลาล่าสุด
fputs($f, $usertime."\n".$contenttime);
fclose($f);
}
//คืนค่ารายการ user
if ($mytime!=$usertime || $mytime==0) $dat=$usertime.chr(6).implode(chr(5), $useronline_list).chr(6);
else $dat="0".chr(6)."0".chr(6);
//คืนค่ารายการ message
if ($mydata!=$contenttime || $mydata==0) {
$f=fopen($contentdat, "r");
$data=fread($f, filesize($contentdat));
fclose($f);
$dat.=$contenttime.chr(6).$data.chr(6).$mtime;
} else $dat.="0".chr(6)."0".chr(6).$mtime;
echo $dat;
?>