Page 1 of 1

PHP Chat

Posted: Thu Feb 12, 2004 4:31 pm
by d3ad1ysp0rk
http://www.404-design.net/chat/chat.php

IFrame refreshes every 2 seconds.

Can you guys give me some ideas on how to improve it? My friend was right, constant refreshing is annoying, but it's the only way I've thought of to do it if theres a lot of ppl in the room..

Posted: Thu Feb 12, 2004 4:36 pm
by markl999
PHP isn't great for this, might want to use one of the many cgi/perl/etc scripts out there for doing it *shrug*

Posted: Thu Feb 12, 2004 4:40 pm
by d3ad1ysp0rk
Thanks for the input, and I knew PHP wouldn't be great for it from the start, but I'm stubborn.. and don't know cgi/perl :P
Also, I know you can just copy n paste the scripts, but I like to know what it's doing so I can fix it or edit it later on..

Posted: Thu Feb 12, 2004 7:31 pm
by McGruff
There is a trick I vaguely remember, possibly using frames and js. Try googling around - should track it down pretty quickly.

Posted: Thu Feb 12, 2004 8:42 pm
by Illusionist
i have a similar problem, and would like to look at some of those cgi/perl scripts... but i can't find any!! would anyone happen to know where i could find some?

Posted: Thu Feb 12, 2004 9:43 pm
by d3ad1ysp0rk
Incase anyone wanted to know how I did it, to give me some ideas on how to improve the design or whatever.. go ahead! :)

chat.php

Code: Select all

<?php
session_start();
if($_POST['mode']=="signin"){
   $_SESSION['username'] = $_POST['username'];
}
echo <<<EOM
<html>
<body>
<div align="center">
EOM;
if(isset($_SESSION['username'])){
   echo <<<EOT
   <iframe src="body.php" scrolling="auto" width="500" height="400" marginheight="0" marginwidth="0" vspace="0" hspace="0" name="bodyframe" frameborder="1"></iframe><br />
   <iframe src="bottom.php"  scrolling="no" width="500" height="30" marginheight="0" marginwidth="0" vspace="0" hspace="0" name="bottomframe" frameborder="1"></iframe><br />
EOT;
}
else {
   echo <<<EOT
   Enter a username to use for chatting:<br />
   <form action="chat.php" method="post">
   <input type="text" name="username"><br />
   <input type="hidden" name="mode" value="signin">
   <input type="submit" value="Start Chatting!">
   </form>
EOT;
}
echo "<br /><br />";
include("counter.php");
$myvar1 = getcount("uniq");
echo "Unique Visitors: " . $myvar1 . "<br />";
echo <<<EOZ
</div>
</body>
</html>
EOZ;
?>
body.php

Code: Select all

<?php
echo <<<EOT
<html>
<body>
<script language="javascript">
setTimeout("window.location.reload()", 2000);
</script>

EOT;
include ("chatcontent.txt");
echo "</body>\n</html>";
?>
bottom.php

Code: Select all

<?php
session_start();
if($_POST['submitted']==1){
   $username = $_SESSION['username'];
   $intext = $_POST['intext'];
   $intext = format($intext);
   $chatfile = fopen("chatcontent.txt", "a");
   fwrite($chatfile, "<b>" . $username . "</b>: $intext<br>\n");
   fclose($chatfile);
}
echo <<<EOT
<form action="bottom.php" method="post"><input type="hidden" name="submitted" value="1"><input type="text" size="60" name="intext">&nbsp;&nbsp;<input type="submit" name="submit" value="Send!"></form>
EOT;
function format($input){
   $input = stripcslashes($input);
   $input = str_replace("<script", " ", "$input");
   $input = str_replace("<iframe", " ", "$input");
   $input = str_replace("<div", " ", "$input");
   $input = str_replace("<span", " ", "$input");
   $input = str_replace("<hr", " ", "$input");
}
?>

Posted: Tue Feb 24, 2004 5:30 pm
by Evan
Hello everyone, I have (what I think) is a pretty valid way to refresh a chat, but I need help with the code to get it working, i think it is possible using WHILE and FOR loops, I dont know, i need some help. I will give 50mb free hosting to whoever helps me out... I just REALLY need this done See my post for more info
viewtopic.php?t=18560&highlight=

Posted: Wed Feb 25, 2004 10:38 am
by McGruff
Evan: this is a code topic about chat & refreshing. Try the project help forum - you might find someone to help you out there.

(Or google around for a free script which doesn't "blink").

Posted: Wed Feb 25, 2004 4:25 pm
by Evan
Heh, OK thanks

sorry bout that

Posted: Thu Feb 26, 2004 4:09 am
by twigletmac
Could you allow users to choose how often they want the screen to refresh, set it as a session variable or sommat?

Mac

Posted: Thu Feb 26, 2004 5:03 am
by JayBird
have a look at this example. Dunno how it works
http://voc.onio.de/voc.php

Source here
http://vochat.com/

Mark