tomfmason Posted July 19, 2006 Share Posted July 19, 2006 I am creating a live support chat script and am running into a little trouble.The way that I decided to do this was to create a static html page and use fwrite to update the new message. The samples below are very simple.[b]The chat login[/b][code=php:0]<?phpif (empty($nick)) { $error = "nick";}if (isset($nick)) {include('db.php');$sql = mysql_query("INSERT INTO chat(nick) VALUES('$nick')") or die (mysql_error());if (!$sql) { $error = "sql";} $filename = "$nick.html";$handle = fopen($filename, "x+b");$body = "<html><head><meta http-equiv=\"refresh\" content=\"8\"><meta name=\"robots\" content=\"noindex\"></head><body bgcolor=\"#CCCCCC\" text=\"#000000\"><p> Welcome $nick, an operator will be with you shortly.</p><!--Start of chat--><!--end of chat--><font color=\"#000000\">© OWPT 2006</font></p></body></html>";fwrite($handle, $body);fclose($handle);include('chat.php'); } ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Untitled Document</title></head><body><p><h3>Please Enter your nick name</h3></p><?phpif ($error == "nick") { echo "You did not enter a nick name";}if ($error == "sql") { echo "Something when wrong with the MySQL query.";} ?><form action="enter_chat.php" method="post"><input type="text" name="nick" size="20"><input type="submit" name="submit" value="Submit"></form></body></html>[/code]This creates a static html file with the name of there nick. I plan on using the chat id as well. Any suggestions as to do this would be great. For example, the generated page would be named [b]$nick.$chat_id.html[/b] So far this works fine. It creates the html file with out any problems.The problem is with the chat.php. It loads just fine but when I try to enter a new message, I get a 403 access denied error. I know that I have the permissions set properly on my server but I guess that I am not setting them right in the script.[b]The Chat.php[/b][code=php:0]<?phpif (isset($submit)) { if (empty($message)) { $error == "messge"; } $file = "$nick.html"; $fp = fopen($file, 'r+b'); $newline = "$nick: $message<br> "; while (!feof($fp)){ $line = trim(fgets($fp, 1024)); if ($line == '<!--Start of chat-->'){ $fpos = ftell($fp); $rest = fread($fp, filesize($file)); fseek($fp, $fpos, SEEK_SET); fwrite($fp, "\n\n"); fwrite($fp, $newline); fwrite($fp, $rest); } } fclose($fp);}?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Test chat</title></head><body><p><iframe name="chat_box" width="550" height="250" src="<?php echo "$nick" ?>.html">Your browser does not support inline frames or is currently configured not to display inline frames.</iframe></p><form action="chat.php" method="post"><?phpif ($error == "message") { echo "You did not enter a message";} ?><p>Enter your message</p><p><input type="text" name="message"><input type="submit" name="submit" value="send"></p></form></body></html>[/code]I am pretty sure that I have not set the permission properly when opening the file. Any suggestions as to what I am doing wrong or suggetions as to a better way to do this would be great.Thanks,Tom Link to comment https://forums.phpfreaks.com/topic/15053-editing-a-static-html-file/ Share on other sites More sharing options...
tomfmason Posted July 19, 2006 Author Share Posted July 19, 2006 Ok I don't think that explained the error that I was having properly. I get the 403 error that the file is not read able. [code]Access forbidden!You don't have permission to access the requested object. It is either read-protected or not readable by the server.[/code]This is from the chat.php I open the file with the r+ command. I will post the relivant piece of script again.[code=php:0]<?phpif (isset($submit)) { if (empty($message)) { $error == "messge"; } $file = "$nick.html"; $fp = fopen($file, 'r+b'); $newline = "$nick: $message<br> "; while (!feof($fp)){ $line = trim(fgets($fp, 1024)); if ($line == '<!--Start of chat-->'){ $fpos = ftell($fp); $rest = fread($fp, filesize($file)); fseek($fp, $fpos, SEEK_SET); fwrite($fp, "\n\n"); fwrite($fp, $newline); fwrite($fp, $rest); } } fclose($fp);}?>[/code]I think that I am going to set up another test and try posting to a seperate file then using include or header to bring them back to the chat.php or maybe have two frames. One with the $nick.htm and one with the message submit form. If I get it figured out I will post the fix.In the mean time any suggestions would be great.Thanks,Tom Link to comment https://forums.phpfreaks.com/topic/15053-editing-a-static-html-file/#findComment-60632 Share on other sites More sharing options...
tomfmason Posted July 19, 2006 Author Share Posted July 19, 2006 I am now sure that it is the way that I calling to open the file. When I login and create the static html file I am redirected to the chat.php and it shows the $nick.html inside the frame but when I add a new message that is when I get the error that the file is not readable. Not sure what the problem is but I am officaly lost. I tried createing another file called add_message.php and posted the new message to it then included the chat.php again. I got the same result. So I now that There is a problem with the way that I am calling the file to be opened. Also it is not writting the new message to the file. Link to comment https://forums.phpfreaks.com/topic/15053-editing-a-static-html-file/#findComment-60644 Share on other sites More sharing options...
tomfmason Posted July 19, 2006 Author Share Posted July 19, 2006 I looked at the source and it is not passing the $nick variable around the second time. here is the source code for chat.php after the a new message has been submited.<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Test chat</title></head><body><p><iframe name="chat_box" width="550" height="250" src=".html">Your browser does not support inline frames or is currently configured not to display inline frames.</iframe></p><form action="chat.php" method="post"><p>Enter your message</p><p><input type="text" name="message"><input type="submit" name="submit" value="send"></p></form></body></html>Any ideas why the $nick variable is not being passed the second time. Link to comment https://forums.phpfreaks.com/topic/15053-editing-a-static-html-file/#findComment-60653 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.