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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Evan
Forum Newbie
Posts: 11
Joined: Tue Feb 24, 2004 5:14 pm
Location: Hell
Contact:

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

Post 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]
davy2001
Forum Commoner
Posts: 37
Joined: Tue Feb 24, 2004 5:59 pm

Post by davy2001 »

i honestly dont have a clue
Evan
Forum Newbie
Posts: 11
Joined: Tue Feb 24, 2004 5:14 pm
Location: Hell
Contact:

Post by Evan »

OK, thank you for your input.... next?
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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..
Evan
Forum Newbie
Posts: 11
Joined: Tue Feb 24, 2004 5:14 pm
Location: Hell
Contact:

Post by Evan »

Well, I would like to stay away from META refresh, because the blink is HORRIBLE..... no one likes that... Anyone else?
Evan
Forum Newbie
Posts: 11
Joined: Tue Feb 24, 2004 5:14 pm
Location: Hell
Contact:

Post 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.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
Evan
Forum Newbie
Posts: 11
Joined: Tue Feb 24, 2004 5:14 pm
Location: Hell
Contact:

Post 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!
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

check this out
Evan
Forum Newbie
Posts: 11
Joined: Tue Feb 24, 2004 5:14 pm
Location: Hell
Contact:

Post 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!
Evan
Forum Newbie
Posts: 11
Joined: Tue Feb 24, 2004 5:14 pm
Location: Hell
Contact:

Post 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!
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

np, i had a similar problem and used that same idea and got it to work!
Evan
Forum Newbie
Posts: 11
Joined: Tue Feb 24, 2004 5:14 pm
Location: Hell
Contact:

Post 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...
Post Reply