Page 1 of 1

PHP Iframe chat.... (chat refresh method)

Posted: Tue Feb 24, 2004 5:14 pm
by Evan
Hey everyone, sorry this is a long post, this is my first time ever posting in a forum; I hope someone can help me out:

Ok, i have a php chat i am coding 100% from scratch, I am ALMOST done, but i need to get this one LAST code working... the chat window (were the messages are displayed) is an iframe above a text box and submit button... Following? OK, well I have it post new messages to an HTML file in this format:

Code: Select all

<b><font color=red>$username: </b></font><font>$message</font><br>
I want the iframe to post the latest message, but i dont want to use the conventional meta refresh... so i came up with this...
The PHP will check the filesize of the messages.html file....
Then it will loop a command that compares the filesize to what the filesize was when it first checked.... If it notices a change in filesize (because a message was saved to the file), it will grab the last line of the HTML file, and put it to a variable, then print "$that_variable'; and then loop to the begining of the file and start all over.... therfore, as soon as a message is sent, it should post imidiatly..... This is the code I came up with, and i know it is wrong, I just wrote it to give an idea of what i need to do...

Code: Select all

<? 
Set loop point
$room = $_GET['room'];
$filesize1 = filesize("rooms/chat_$room.html");
$filesize2 = filesize("rooms/chat_$room.html");
While ($filesize1 == $filesize2):
$filesize2 = filesize("rooms/chat_$room.html");
Endwhile;
fopen rooms/chat_$room.html..
get last line of chat_$room.html, and set to variable $message
echo '$message';
Goto loop point
?>
ANY HELP WOULD BE GREAT!!! THANKS!

?>[/php_man]

Posted: Tue Feb 24, 2004 5:59 pm
by davy2001
i honestly dont have a clue

Posted: Tue Feb 24, 2004 6:08 pm
by Evan
OK, thank you for your input.... next?

Posted: Tue Feb 24, 2004 6:44 pm
by d3ad1ysp0rk
Why not have your latest one be <a name="bottom"> then have it refresh to

body.html#bottom

??


btw:
http://www.optikhosting.com/~des404/chat/chat.php


IM me if you want the code.. heck, might even help you.. although I kind of scrapped the project as the refresh is really annoying..

Posted: Tue Feb 24, 2004 7:25 pm
by Evan
Well, I would like to stay away from META refresh, because the blink is HORRIBLE..... no one likes that... Anyone else?

Posted: Wed Feb 25, 2004 4:59 pm
by Evan
Hey everyone, I just tried this code to see if it would print 'message sent' once the filesize changes, but im not getting anything... I personaly dont see any problem in the code, mabey you guys can find sumtin....

Code: Select all

<?
$room = $_GET['room'];
$filesize1 = filesize("rooms/chat_$room.html");
$filesize2 = filesize("rooms/chat_$room.html");
while($filesize1 == $filesize2)
{
$filesize2 = filesize("rooms/chat_$room.html");
sleep(1);
}
print 'MESSAGE SENT';
?>
Any idea's? I wanna just make sure this will at least work before i continue... I dont think it is breaking out of the loop for some reason.

Posted: Wed Feb 25, 2004 9:58 pm
by McGruff
I vaguely remember finding something with google one day which might (or might not) have used frames & js. Refresh a hidden frame (?), then update the viewed frame with js(?) - thus avoiding the blink.

Sorry no links.

Posted: Wed Feb 25, 2004 10:00 pm
by Evan
I have spent 4 days now searching google and 7 hours a day at school trying to think up a method... If someone has a link PLEASE share!

Posted: Thu Feb 26, 2004 6:46 am
by Illusionist
check this out

Posted: Thu Feb 26, 2004 7:21 am
by Evan
AWSOME!! Thanks so much you guys... I gotta go now but I am going to take a look at that script as soon as I get home and hopfully get it to work!

Posted: Thu Feb 26, 2004 4:18 pm
by Evan
AWSOME EVERYONE!! I GOT IT WORKING!! Thanks soooo much you all! I will post a link in a couple hours once i clean it up! Thanks again for all your help!

Posted: Thu Feb 26, 2004 4:19 pm
by Illusionist
np, i had a similar problem and used that same idea and got it to work!

Posted: Thu Feb 26, 2004 4:51 pm
by Evan
OK, I got this all done but here is my problem.. I had been using this to load the iframe at the bottom of the page...

Code: Select all

<body onLoad='self.scrollTo(0,document.body.scrollHeight)'>
BUT... once the chat gets about twice the height of the iframe, it starts loading at the top then flashing to the bottom.... any other ideas? Im searching google as we speak... It also flashes to the bottom like that when a smilie is sent...
If you want to see an online example....
http://mtdm.no-ip.org:81/login/chat/start.html
...disable popup blockers so my logout script can run please...