PHP做的服务器端的PUSH(推送) <? /*-------------------------------------------------------------------------- Server push PHP3 script A very short routine to perform simple server push animation, with browser detection snippset. Server push work's only with Netscape 4.0 or higher. Author: Fabian Dennler, [email protected] Date:01.05.2000
Insert the server push script like an image in your html file. i.e. <IMG SRC="campush.php3"> ------------------------------------------------------------------------------------*/ // filelocation of the webcam image $filename= "cam.jpg"; // how many time between push // for unbuffered output set to 1. $pause = "10"; // how many time to pass to passthru fun // ction , don't set this to high for serve // r usage $PASSES = 20;
/*------------------------------------------------------------------------------------ for ($j=0;$j<=$PASSES;$j++) { $img[count($img)] = $filename; } /*------------------------------------------------------------------------------------ /*------------------------------------------------------------------------------------*/ /* Plot the Currrent Data Block of the image */ /*------------------------------------------------------------------------------------*/ function plot_cam() { global $filename,$img,$pause; $k = 0; Header("Content-type: multipart/x-mixed-replace;boundary=ThisRandomString"); while ($img[$k]==$filename) { print("n--ThisRandomStringnn"); Header("Content-type: text/plain"); $cam = fopen($filename,"r"); fpassthru($cam); fclose($cam); if ($pause) { sleep($pause);} // time between reload, usefull for server usage $k++; if ($k==count($img)) { echo("n--ThisRandomString--n"); } } } /**************************************************************************************/ Broser Detection is provided by Leon Atkinson <[email protected]> /*------------------------------------------------------------------------------------*/ /* Get the name the browser calls itself and what version */ $Browser_Name = strtok($HTTP_USER_AGENT, "/"); $Browser_Version = strtok(" "); /* MSIE lies about its name */ if(ereg("MSIE", $HTTP_USER_AGENT)) { $Browser_Name = "MSIE"; $Browser_Version = strtok("MSIE"); $Browser_Version = strtok(" "); $Browser_Version = strtok(";"); } /* Opera isn't completely honest, either ... */ /* Modificaton by Chris Mospaw <[email protected]> */ if(ereg("Opera", $HTTP_USER_AGENT)) { $Browser_Name = "Opera"; $Browser_Version = strtok("Opera"); $Browser_Version = strtok("/"); $Browser_Version = strtok(";"); } /* try to figure out what platform, windows or mac */ $Browser_Platform = "unknown"; if(ereg("Windows",$HTTP_USER_AGENT) || ereg("WinNT",$HTTP_USER_AGENT) || ereg("Win95",$HTTP_USER_AGENT)) { $Browser_Platform = "Windows"; } if(ereg("Mac", $HTTP_USER_AGENT)) { $Browser_Platform = "Macintosh"; } if(ereg("X11", $HTTP_USER_AGENT)) { $Browser_Platform = "Unix"; } if(($Browser_Platform == "Windows")){ if($Browser_Name == "Mozilla") { if($Browser_Version >= 3.0) { } // SERVER PUSH WORK'S ONLY HERE :) if($Browser_Version >= 4.0) { plot_cam(); } } } elseif($Browser_Platform == "Macintosh") { if($Browser_Name == "Mozilla") { if($Browser_Version >= 3.0) { } // SERVER PUSH WORK'S ONLY HERE :) if($Browser_Version >= 4.0) {plot_cam();} } } elseif($Browser_Platform == "Unix") { if($Browser_Name == "Mozilla") { if($Browser_Version >= 3.0) { } // SERVER PUSH WORK'S ONLY HERE :) if($Browser_Version >= 4.0) { plot_cam();} } } exit; ?>
to dynku:在主动服务器机构中,安全验证只有在用户接入是发生,一旦用户通过验证接入,就被认为是合法用户,在以后的数据传输中,将不再进行合法性认证。这种模型的不安全性在于:如果有人能够骗取认证成为合法用户,就可以发送非法数据以攻击服务器,这就是关键所在。一般黑客的做法是:监听端口,分析数据包,找出认证部分,再伪造数据。这样的话就明白啦,合法性认证的关键就是认证信息的保密性,你说的加密是个好办法,不同的系统有不同的策略,安全第一,呵呵!
你比我快!!!7456
具体这个问题并不难做,来个最笨的方法:定期发请求也可以搞定。如果强调实时相应,则不能使用定期的做法,不知道socket能不能做到。
其实,象oicq那样,在服务器上保存client 的数据(ip &port)
然后数据更新时由server 连接client ,用socket应该可以解决,不过这样很容易受到攻击
This is Document ONE!
Here's some text.
如果将它载入支持动态文档的浏览器(Netscape 1.1以上,Internet Explorer和Mosaic也支持客户端拖曳),它将每隔一秒将自己重载一次。 由于META元素实际是在HTML文档中模拟HTTP响应头标,所以它能够告知浏览器将自身信息当作HTTP响应使用。上例中的META标记相当于: Refresh:1 这样,实际上就是HTTP头标告知浏览器每一秒更新一次文档。如果需要延时是12秒,那么就是这样的指令: 那么它等效于: Refresh:12 关于客户端的拖曳我也懒的继续写下去,关于怎么使客户端自动申请其他URL的数据话,请使用如下: 注意的是,此处的URL不能使用相对路径,必须全部指定。 其中时间间隔可以设置为0,这样浏览器在当前文档显示完毕后,以最快的速度载入新的数据!
这种方法应该可以满足吧!
<?
/*-------------------------------------------------------------------------- Server push PHP3 script
A very short routine to perform simple server push animation,
with browser detection snippset. Server push work's only with
Netscape 4.0 or higher.
Author: Fabian Dennler, [email protected]
Date:01.05.2000
Insert the server push script like an image in your html file.
i.e. <IMG SRC="campush.php3">
------------------------------------------------------------------------------------*/
// filelocation of the webcam image
$filename= "cam.jpg";
// how many time between push
// for unbuffered output set to 1.
$pause = "10";
// how many time to pass to passthru fun
// ction , don't set this to high for serve
// r usage
$PASSES = 20;
/*------------------------------------------------------------------------------------
for ($j=0;$j<=$PASSES;$j++) {
$img[count($img)] = $filename;
}
/*------------------------------------------------------------------------------------
/*------------------------------------------------------------------------------------*/
/* Plot the Currrent Data Block of the image */
/*------------------------------------------------------------------------------------*/
function plot_cam() {
global $filename,$img,$pause;
$k = 0;
Header("Content-type: multipart/x-mixed-replace;boundary=ThisRandomString");
while ($img[$k]==$filename) {
print("n--ThisRandomStringnn");
Header("Content-type: text/plain");
$cam = fopen($filename,"r");
fpassthru($cam);
fclose($cam);
if ($pause) { sleep($pause);} // time between reload, usefull for server usage
$k++;
if ($k==count($img)) {
echo("n--ThisRandomString--n");
}
}
}
/**************************************************************************************/
Broser Detection is provided by Leon Atkinson <[email protected]>
/*------------------------------------------------------------------------------------*/
/* Get the name the browser calls itself and what version */
$Browser_Name = strtok($HTTP_USER_AGENT, "/");
$Browser_Version = strtok(" ");
/* MSIE lies about its name */
if(ereg("MSIE", $HTTP_USER_AGENT)) {
$Browser_Name = "MSIE";
$Browser_Version = strtok("MSIE");
$Browser_Version = strtok(" ");
$Browser_Version = strtok(";");
}
/* Opera isn't completely honest, either ... */
/* Modificaton by Chris Mospaw <[email protected]> */
if(ereg("Opera", $HTTP_USER_AGENT)) {
$Browser_Name = "Opera";
$Browser_Version = strtok("Opera");
$Browser_Version = strtok("/");
$Browser_Version = strtok(";");
}
/* try to figure out what platform, windows or mac */
$Browser_Platform = "unknown";
if(ereg("Windows",$HTTP_USER_AGENT)
|| ereg("WinNT",$HTTP_USER_AGENT)
|| ereg("Win95",$HTTP_USER_AGENT)) {
$Browser_Platform = "Windows";
}
if(ereg("Mac", $HTTP_USER_AGENT)) {
$Browser_Platform = "Macintosh";
}
if(ereg("X11", $HTTP_USER_AGENT)) {
$Browser_Platform = "Unix";
}
if(($Browser_Platform == "Windows")){
if($Browser_Name == "Mozilla") {
if($Browser_Version >= 3.0) {
}
// SERVER PUSH WORK'S ONLY HERE :)
if($Browser_Version >= 4.0) { plot_cam(); }
}
}
elseif($Browser_Platform == "Macintosh") {
if($Browser_Name == "Mozilla") {
if($Browser_Version >= 3.0) {
}
// SERVER PUSH WORK'S ONLY HERE :)
if($Browser_Version >= 4.0) {plot_cam();}
}
}
elseif($Browser_Platform == "Unix") {
if($Browser_Name == "Mozilla") {
if($Browser_Version >= 3.0) {
}
// SERVER PUSH WORK'S ONLY HERE :)
if($Browser_Version >= 4.0) { plot_cam();}
}
}
exit;
?>
我对安全方面了解不多,不过我想,如果使用过高的加密算法,是否会影响性能呢?
希望能有高手说明.我觉得如果用applet 定期发送信息对带宽的浪费太大了,还是server 端主动一些好,省带宽
不过有了他,可以试试移植到java