Jump to content


Photo

Javascript/HTML/PHP Chatroom


  • Please log in to reply
1 reply to this topic

#1 0p3n_p0rT

0p3n_p0rT
  • Members
  • Pip
  • Newbie
  • 3 posts

Posted 25 March 2006 - 01:36 AM

Hi,
I recently made a chatroom in php. All messages are written to a chat log, and that chat log is what is read in the conversation screen, which is an iframe. However, I need the frame to refresh every 2 seconds or so, so that it is constantly updated.

At the moment, I am using:
<META HTTP-EQUIV="Refresh" CONTENT="2"; URL="chatlog.htm">

However, whenever it refreshes and the length of the chat goes beyond the iframes capacity, a scroll bar appears. I want it to automatically keep to the bottom, as whenever it refreshes, it takes the browser to viewing the top part of the iframe. Also, whenever there is a new message, I want it to automatically scroll down to it so it is in view.

How could I do this?

Also, with the PHP:
I have a "connected" list. Whenever someone joins the page, the username from their session is logged to "connected.php". However, I want it to be removed when they exit the chat. Not all people would use a "logout" button so I would need it to somehow remove their name from the connected log file when their session is killed. How could I do that?

#2 Gast

Gast
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts
  • LocationSouth East England

Posted 25 March 2006 - 12:16 PM

[!--quoteo(post=358114:date=Mar 25 2006, 01:36 AM:name=0p3n_p0rT)--][div class=\'quotetop\']QUOTE(0p3n_p0rT @ Mar 25 2006, 01:36 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hi,
I recently made a chatroom in php. All messages are written to a chat log, and that chat log is what is read in the conversation screen, which is an iframe. However, I need the frame to refresh every 2 seconds or so, so that it is constantly updated.

At the moment, I am using:
<META HTTP-EQUIV="Refresh" CONTENT="2"; URL="chatlog.htm">

However, whenever it refreshes and the length of the chat goes beyond the iframes capacity, a scroll bar appears. I want it to automatically keep to the bottom, as whenever it refreshes, it takes the browser to viewing the top part of the iframe. Also, whenever there is a new message, I want it to automatically scroll down to it so it is in view.

How could I do this?

Also, with the PHP:
I have a "connected" list. Whenever someone joins the page, the username from their session is logged to "connected.php". However, I want it to be removed when they exit the chat. Not all people would use a "logout" button so I would need it to somehow remove their name from the connected log file when their session is killed. How could I do that?
[/quote]

For the refreshing, when you generate the results of the chat, then add an anchor link to the last result:

<a name="latestmsg"></a>

Then refresh with:

<META HTTP-EQUIV="Refresh" CONTENT="2"; URL="chatlog.htm#latestmsg">

For the PHP, the only way I think possible is to use AJAX. Take a look at the links in my sig at learning how to use it, but basically you can send a request using the "onabort" event:

<body onabort="sendRequest('logout', '<? echo $_SESSION['user_id']; ?>');">

Or something similar, as you cannot actually execute a PHP function with a JS event handler. Hope that helps! :)

OS and Internet Specs:
Windows XP (with SP2), 1680x1050, PHP 4, MySQL 3, Internet Explorer 6 &7 /FireFox 2.0/Opera 9.2

Tutorials:
Simple Introduction to AJAX and XMLHttpRequest
Creating Live Data with AJAX Making a Google Suggest like application




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users