<?php // plug-in 54: post to chat
/* * 外掛程式說明:
* 外掛程式將向乙個聊天室傳送乙個聊天資訊並支援幾個引數。若傳送成功,則本外掛程式返回1,如果檔案不能寫入,則返回-1。
* 如果用泛洪控制阻止乙個重複內容,則返回0。如果$message為空內容或者在$to或者$from裡包含非法符合,則返回-2。
* 本外掛程式需要輸入以下引數:
* $datafile 字串,表示聊天記錄檔案儲存的位置。
* $maxposts 一次可以保留的最多聊天記錄數。
* $maxlength 聊天記錄的最大長度,單位為字元。
* $from 傳送聊天訊息的使用者名稱。
* $to 接收聊天訊息的使用者名稱,如果為空,則表示聊天內容可以公開。
* $message 聊天內容。
* $floodctrl 泛洪控制,如果值為on,同乙個使用者的重複內容不可以重**送$maxposts次。
*/// this is an executable example with additional code supplied
// to obtain just the plug-ins please click on the download link
if (!isset($_post['from']))
$from = $_post['from'];
$to = $_post['to'];
$message = $_post['message'];
$maxposts = 20;
$maxlength = 1024;
$result = piphp_posttochat('chatroom.txt', $maxposts,
$maxlength, $from, $to, $message, 'off');
echo "first posting of message
";echo "message '$message' from user '$from' to user '$to': ";
if ($result == 1) echo "successfully posted";
elseif ($result == -1) echo "not posted (could not access file)";
elseif ($result == -2) echo "no message to post or illegal '|'";
else echo "not posted due to flooding control";
$result = piphp_posttochat('chatroom.txt', $maxposts,
$maxlength, $from, $to, $message, 'off');
echo "
posted again with no flooding control...
";echo "message '$message' from user '$from' to user '$to': ";
if ($result == 1) echo "successfully posted";
elseif ($result == -1) echo "not posted (could not access file)";
elseif ($result == -2) echo "no message to post or illegal '|'";
else echo "not posted due to flooding control";
$result = piphp_posttochat('chatroom.txt', $maxposts,
$maxlength, $from, $to, $message, 'on');
echo "
..and with flooding control
";echo "message '$message' from user '$from' to user '$to': ";
if ($result == 1) echo "successfully posted";
elseif ($result == -1) echo "not posted (could not access file)";
elseif ($result == -2) echo "no message to post or illegal '|'";
else echo "not posted due to flooding control";
function piphp_posttochat($datafile, $maxposts, $maxlength,
$from, $to, $message, $floodctrl)
if ($message == "" || strpos($from, '|') ||
strpos($to, '|')) return -2;
$message = str_replace('|', '|', $message);
$message = substr($message, 0, $maxlength);
$fh = fopen($datafile, 'r+');
if (!$fh) return -1;
flock($fh, lock_ex);
fgets($fh);
$text = fread($fh, 100000);
if (strtolower($floodctrl) == 'on' &&
strpos($text, "|$to|$from|$message\n"))
$lines = explode("\n", $text);
$temp = explode('|', $lines[$maxposts - 2]);
$text .= ($temp[0] + 1) . "|$to|$from|$message\n";
fseek($fh, 0);
fwrite($fh, $text);
ftruncate($fh, strlen($text));
flock($fh, lock_un);
fclose($fh);
return 1;
}?>
外掛程式82 傳送Ajax請求
the contents of this div will be replaced ajaxpost.php if isset post url echo file get contents post url 外掛程式說明 本外掛程式接受乙個網頁的url位址,若個引數和乙個文件物件模型 dom 把操...
UDP聊天器01 傳送資料
使用udp傳送資料 import socket def main 建立udp套接字 udp socket socket.socket socket.af inet,socket.sock dgram while true 使用互動式進行傳輸資料 send data input 請輸入要傳送的資料 使...
八 傳送郵件
傳送郵件 如下 from email.mime.text import mimetext from email.header import header import smtplib import datetime from poseidon.myutil import myutil import ...