当前位置:Gxlcms > PHP教程 > php页面静态刷新_PHP

php页面静态刷新_PHP

时间:2021-07-01 10:21:17 帮助过:36人阅读

Requirements
Works with Apache-1.3.14/PHP4.0.3pl1 server and Various Netscape clients. Probably many other server combos. Tested on Netscape 4.7x and 6.0/Mozilla.
Does NOT WORK WITH IE. Internet Exploiter does not support x-mixed-replace server-push as far as I know. If a browser has "MSIE" in its User-Agent string the script will display one image and exit.

Update 20020108: Poked around freshmeat for a bit and found Andy Wilcock's Cambozola java applet which seems to work well with my php script to make the stream viewable under IE. Beware that the current version doesn't work under "Name-based" virtual hosts but I'll have a patch for it soon.
Source
Download

$file = "./latest.jpg";
$sep = "gIrLsKiCkAsSiTsAySsOoNaTsHiRt";

if (ereg(".*MSIE.*",$HTTP_SERVER_VARS["HTTP_USER_AGENT"]))
{
# If IE, spit out one pic and exit
header("Cache-Control: no-cache");
header("Pragma: no-cache");
header("Content-type: image/jpeg");
header("Content-size: " . filesize($file));
readfile($file);
}
else
{
# if not IE, give the browser a try
header("Content-Type: multipart/x-mixed-replace; boundary=$sep");
print "--$sep\n";
do {
print "Content-Type: image/jpeg\n\n";
readfile($file);
print "\n--$sep\n";
flush();
$mt = filemtime($file);
do {
sleep (1);
# we won't output the same image twice.
clearstatcache();
} while ($mt == filemtime($file));
} while (1);
}
?>


Make sure there are no blank lines outside the in your script. That will cause screwey headers to be sent too soon.
Reference the script in your HTML page as if it was an image:



Use this bit of PHP on the page that references the image to compensate for IE's lack of "innovation":


if (ereg("MSIE",$HTTP_SERVER_VARS["HTTP_USER_AGENT"])) {
echo "\n";
}
?>

人气教程排行