Posted by rey Wed 7th Mar 2007 13:28 - Syntax is PHP - 17 viewsRun this post in the PHP shell
Download | New Post | Modify | Hide line numbers
PHP parser reported no syntax errors in this post!
  1. $start_time=microtime(true);
  2. //For AJAX!!
  3.  
  4. $chatpage="chat.xml";
  5. if (isset($_POST['send']))
  6. {
  7.     $send=$_POST['send'];
  8. }
  9. else
  10. {
  11.     $send=3;
  12. }
  13. $post=0;
  14. $showchat=0;
  15. $json= '';
  16. $name = htmlspecialchars($_POST['name'], ENT_QUOTES);
  17.  
  18.  
  19. if ($send=='1')  // If somebody SENT a message
  20. {
  21.     $message= $_POST['message'];
  22.     $post=1;
  23. }
  24. elseif ($send=='2')  // If somebody wants ALL messages
  25. {
  26.     $showchat='all';
  27. }
  28. elseif ($send=='3')  // If somebody wants NEW messaages
  29. {
  30.     if (isset($_SESSION['lastid']))
  31.     {
  32.         $last=$_SESSION['lastid'];
  33.     }
  34.     else //should never happen... but who knows
  35.     {
  36.         $last=$_POST['last_id'];
  37.         $_SESSION['lastid']=$last;
  38.     }
  39.     $showchat='new';
  40. }
  41.  
  42.  
  43. $user="guest";
  44. $password="fottilaetispiezoindue";
  45. $database="naerey";
  46. $server='switch-case.org';
  47. $link=mysql_connect($server,$user,$password);
  48. mysql_select_db($database,$link) or die( "Unable to select database");
  49.  
  50. if ($post)
  51. {
  52.     $message = htmlspecialchars($message, ENT_QUOTES);
  53.     $message = wordwrap($message, 25, " ", 1);
  54.     $smileys = array ('>:)',':(',':D',':/',';)',':|',':)','O_O','>_<',':p',':P',
  55.         'woot','rofl','ouch','lol','love','<3','lmao');
  56.     $smilhtml= array ('','',
  57.         '','',
  58.         '','',
  59.         '','',
  60.         '','',
  61.         '','',
  62.         '','',
  63.         '','',
  64.         '','');
  65.     $message= str_replace($smileys,$smilhtml,$message);
  66.     //Smileys!
  67.    
  68.     $date_=date("d/m/y");
  69.     $time_=date("H:i:s");
  70.     $ip_=$_SERVER['REMOTE_ADDR'];
  71.     $query="INSERT INTO `chat_history` values ( '', '$ip_', '$date_', '$time_', '$name', '$message')";
  72.     $result=mysql_query($query,$link);
  73.    
  74.     $time_=date("His");$date_=date("d/m/y");
  75.     $query ="INSERT INTO chat_users VALUES ('$ip_', '$date_', '$time_', '$name', '1') ";
  76.     $query.="ON DUPLICATE KEY UPDATE date='$date_',time='$time_',posts=posts+1,name='$name' ";
  77.     $result=mysql_query($query,$link);
  78. }
  79.  
  80.  
  81. if ($showchat=='all')
  82. {
  83.     $query="SELECT id,name,message,time FROM ( SELECT id,name,message,time FROM ";
  84.         $query.="chat_history ORDER BY id DESC LIMIT 10 ) AS tmp ORDER BY id";
  85.     $result=mysql_query($query,$link);
  86.     $num=mysql_num_rows($result);
  87.     $i=0;
  88.     while ($i < $num)
  89.     {
  90.         $_name=mysql_result($result,$i,"name");
  91.         $_message=mysql_result($result,$i,"message");
  92.         $_id=mysql_result($result,$i,"id");
  93.         $_time=mysql_result($result,$i,"time");
  94.         $json.= "\n

    $_time $_name: $_message

    "
    ;
  95.         ++$i;
  96.     }
  97.    
  98.     $date_=date("d/m/y");
  99.     $time_=date("His");
  100.     $ip_=$_SERVER['REMOTE_ADDR'];
  101.     $query ="INSERT INTO chat_users VALUES ('$ip_', '$date_', '$time_', '$name', '1') ";
  102.     $query.="ON DUPLICATE KEY UPDATE date='$date_',time='$time_',name='$name' ";
  103.     $result=mysql_query($query,$link);
  104. }
  105. elseif($showchat=='new')
  106. {
  107.     $query="SELECT id,name,message,time FROM chat_history WHERE id>$last";
  108.     $result=mysql_query($query,$link);
  109.     $num=mysql_num_rows($result);
  110.     $i=0;
  111.     while ($i < $num)
  112.     {
  113.         $_name=mysql_result($result,$i,"name");
  114.         if ($_name==$name)
  115.         {
  116.             $_name='You';
  117.         }
  118.         $_message=mysql_result($result,$i,"message");
  119.         $_id=mysql_result($result,$i,"id");
  120.         $_time=mysql_result($result,$i,"time");
  121.         $json.= "\n

    $_time $_name: $_message

    "
    ;
  122.         ++$i;
  123.     }
  124.    
  125.     $date_=date("d/m/y");
  126.     $time_=date("His");
  127.     $ip_=$_SERVER['REMOTE_ADDR'];
  128.     $query ="INSERT INTO chat_users VALUES ('$ip_', '$date_', '$time_', '$name', '1') ";
  129.     $query.="ON DUPLICATE KEY UPDATE date='$date_',time='$time_'";
  130.     $result=mysql_query($query,$link);
  131. }
  132.  
  133.  
  134. if(!$post){$query="SELECTmax(id)FROMchat_history";$result=mysql_query($query,$link);$id=mysql_result($result,0,"max(id)");$users='';$_date=date("d/m/y");$_time=date("His")-14;$users="
      "
    ;$query="SELECTnameFROMchat_usersWHEREdate='$_date'ANDtime>$_time";$result=mysql_query($query,$link);$num=mysql_num_rows($result);$i=0;while($i<$num){$_user=mysql_result($result,$i,"name");$users.="\n.'"'.$_user.'"'.")'>$_user";++$i;}if(!$num){$users.="\n
  135. none
  136. ";}$users.="\n";$end_time=microtime(true)-$start_time;$total_time=number_format($end_time,4);$jsonObj=array('dowhat'=>$send,'chat'=>$json,'last_id'=>$id,'users'=>$users,'time'=>$total_time);$_SESSION['lastid']=$id;}else{$end_time=microtime(true)-$start_time;$total_time=number_format($end_time,4);$jsonObj=array ('dowhat'=>'1','time'=>$total_time);}mysql_close();echo json_encode($jsonObj);?>

PermaLink to this entry https://pastebin.co.uk/11525
Posted by rey Wed 7th Mar 2007 13:28 - Syntax is PHP - 17 viewsRun this post in the PHP shell
Download | New Post | Modify | Hide line numbers

 

Comments: 0