What am I doing incorrectly in my code? Let me explain, I'm trying to write a chat application for my school, and for users to freely switch between .txt databases, I made a simple form and If...Then statement that switches $file = 'chatmsg.txt' to $file = 'indexmsg.txt'. I thought I had it correctly, but apparently not. What am I doing wrong? Thanks for your input.
if (isset($HTTP_GET_VARS['f1']))
{
$f2 = file($file) ;
echo("<html><head><title></title><meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head>") ;
echo("<body text=#0000cc><meta http-equiv='refresh' content='{$refresh}; url={$HTTP_SERVER_VARS['REQUEST_URI']}'>") ;
echo("<font color=#e22200>Online Users: ") ;
foreach($users as $u) echo "<font color=#ee0099>".$u."</font> - " ;
echo "</font><hr>" ;
for($i=0; isset($f2[$i]) && $i<$max; $i++) {
$e=explode("||", $f2[$i]) ;
if ($e[2]!="\r\n") echo "<font color=green>{$e[0]}</font> <font color=red>:</font> {$e[2]}开发者_开发技巧<br>\r\n" ;
}
die("</body></html>") ;
}
else
{
$html = <<<EOA
<html><head><title>KeyChat</title><meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<script><!--
function msg(){ document.m.msg.focus(); } // --></script>
</head>
<body align='center' onLoad='msg()'> <center>
<iframe src='?f1=1' width='95%' height='70%'></iframe><br>
<table width='95%'><tr><td align='center' width='100%'>
<form action='' method='post' name='m'>
Message : <input name='msg' size=60> <input type='submit' name='send' value='Send'>
<br />
</form>
</td></tr></table>
<h3>Welcome to KeyChat</h3>
<p><big>NOTICE: Please chat at home, not at school. If you chat at school, do realize that you hold all responsibility for not taking seriously this notice.</p></big>
<form name="name" action="test.php?name=Aaron" method="post">
<input type="radio" name="name" value="Aaron" /> Aaron<br />
<input type="radio" name="name" value="Benjamin" /> Benjamin<br />
<input type="submit" value="Submit">
EOA;
die($html);
}
if(empty($_REQUEST["name"]))
echo "No POST variables" ;
else
$file = 'indexmsg.txt' ;
Looks to me like the problem is your use of die(), which does output text, but it also stops the execution of the script.
$file never gets a new value because you called die() before it. Change the two instances of die() to echo(), and it should work.
精彩评论