我使用以下 PHP 代码检查 IP 和端口状态。有用!然后我做了一个刷新按钮来重置显示的状态,这样人们就不需要按F5了。嵌入状态显示“刷新”,但 IP 检查似乎不起作用。
这是 PHP IP 检查:
function check($host,$port)
{
if(isset($host) && isset($port)){
$fp = @fsockopen($host, $port, $errno, $errstr, 0.5);
if(!$fp){
$outp = '"onlinestatus/offline.swf"';
}
elseif($fp){
$outp = '"onlinestatus/online.swf"';
}
} else {
$outp = 'null';
}
return ($outp);
}
?>
这是嵌入控件:
<script type="text/javascript">
function reloadembed() {
var game=document.getElementById("embed1");
var clone=game.cloneNode(true);
clone.setAttribute('src',<? echo check($host,$port); ?>);
game.parentNode.replaceChild(clone,game)
}
</script>
这是刷新按钮:
<a href="javascript:"
onmousedown="document.images['Refresh'].src='image/button_reresh_click.png'"
onmouseup="document.images['Refresh'].src='image/button_reresh_down.png'"
onClick="reloadembed();"
onMouseOver="document.images['Refresh'].src='image/button_reresh_down.png'"
onMouseOut="document.images['Refresh'].src='image/button_reresh_up.png'">
<img name="Refresh" src="image/button_reresh_up.png">
</a>