jimmybeaches
08-15-2004, 04:32 PM
Hello all,
I have two questions:
1.
I created a very simple chat script for talking to a friend. When I am using Mozilla, I can enter data into the textbox and click Submit OR push enter, but when using Internet Explorer I HAVE to click the submit button. Sometimes the message is submitted when I push Enter, but not always. It always works when clicking the submit button... ???
Question 2.
When my friend enters a message, it is written to the chatfile (text file) like so:
$date|$ipaddress|$themessage
When I enter "sdf" as a message, this will trigger a delete function. the delete function opens up the chatfile, deletes the contents, and writes "1" to the file. What I am trying to do is when the file only contains "1" then a NO DATA message is displayed. I sort of have this working, but the NO DATA message always shows up ender the messages. Here is my bit of code that reads and displays the contents of the chatfile:
if (!file_exists($chatfile)) {
echo "NO DATA";
} else {
$fp = fopen($chatfile, "r+");
$file_contents = fread($fp, filesize($chatfile));
fclose($fp);
$line = explode("\n", $file_contents);
rsort($line);
$i = 0;
while($i <= sizeof($line)) {
$data_pair = explode("|", $line[$i]);
if ($data_pair[1]==$ip) {
$who = "you";
$message = "you";
} else {
$who = "guest";
$message = "guest";
}
if ($data_pair[1]<=0 || $data_pair[0]=="1") { //
echo "<center><b>NO DATA</b></center>";
break;
} else {
echo <<<END
<span class="details">$data_pair[0]</span>
<br /><br />
$who: <span class="$message">$data_pair[2]</span>
<br /><br />
<hr size="1" color="#666666" noshade>
END;
}
$i++;
}
} // end if file exists statement
Here is the script in action:
http://www.robj.ca/test/
and the source:
http://www.robj.ca/test/chat.txt
Can anyone help me out? :confused:
I have two questions:
1.
I created a very simple chat script for talking to a friend. When I am using Mozilla, I can enter data into the textbox and click Submit OR push enter, but when using Internet Explorer I HAVE to click the submit button. Sometimes the message is submitted when I push Enter, but not always. It always works when clicking the submit button... ???
Question 2.
When my friend enters a message, it is written to the chatfile (text file) like so:
$date|$ipaddress|$themessage
When I enter "sdf" as a message, this will trigger a delete function. the delete function opens up the chatfile, deletes the contents, and writes "1" to the file. What I am trying to do is when the file only contains "1" then a NO DATA message is displayed. I sort of have this working, but the NO DATA message always shows up ender the messages. Here is my bit of code that reads and displays the contents of the chatfile:
if (!file_exists($chatfile)) {
echo "NO DATA";
} else {
$fp = fopen($chatfile, "r+");
$file_contents = fread($fp, filesize($chatfile));
fclose($fp);
$line = explode("\n", $file_contents);
rsort($line);
$i = 0;
while($i <= sizeof($line)) {
$data_pair = explode("|", $line[$i]);
if ($data_pair[1]==$ip) {
$who = "you";
$message = "you";
} else {
$who = "guest";
$message = "guest";
}
if ($data_pair[1]<=0 || $data_pair[0]=="1") { //
echo "<center><b>NO DATA</b></center>";
break;
} else {
echo <<<END
<span class="details">$data_pair[0]</span>
<br /><br />
$who: <span class="$message">$data_pair[2]</span>
<br /><br />
<hr size="1" color="#666666" noshade>
END;
}
$i++;
}
} // end if file exists statement
Here is the script in action:
http://www.robj.ca/test/
and the source:
http://www.robj.ca/test/chat.txt
Can anyone help me out? :confused: