Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Skrypt dodawania komentarzy.
Forum PHP.pl > Forum > Przedszkole
wowo
Witam
Mam taki skrypt talkback, i wkopiowalem wszystko jak trzeba ,poustawialem chmody, ale nie działa.
Prosze mi powiedzieć jak on działa i co on robi smile.gif

  1. [/php]
  2.  
  3. [code][/code]
  4. <?
  5. //updated: 17:15 14/09/2002
  6. ///////////////////////////////////////////////////////////////////////////////
  7. // talkback v1.12 //
  8. // created by James Maglo //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11.  
  12.  
  13. $address = "http://www.xxx.pl//x/"; //Full URL to where the talkback.php script is installed
  14. $file = "comment.dat"; //name of the file where data will be stored. the default comment.dat value is recommended
  15. $path = "public_html/x/";// Finally, the full path to the script directory
  16. $img = "1"; // 1 - user can post images 0 - images are disabled
  17. $title_colour = "#0066AA"; //background colour of the part where user's name is displayed
  18. $message_colour = "#CECEFF"; //background colour of the message displayed
  19.  
  20. // CHMOD THE DIRECTORY WHICH YOU SPECIFIED IN $address TO 0777!!!
  21. //THATS ALL YOU NEED TO EDIT, PLEASE STOP NOW. TO USE THE SCRIPT, USE include("path/to/script/talkback.php");
  22. $version = "1.1";
  23. $maxlen = 30;
  24. $route = "true";
  25. if($img){
  26. $imgnfo = "enabled. \\n\\n[img=http://www.xxx.pl/x/image.jpg][/img]";
  27. }
  28. else{
  29. $imgnfo = "disabled";
  30. }
  31.  
  32. function reWriteDataInFile($fileData,$fileName = "talkback.tb")
  33. {
  34. if(!file_exists($fileName))
  35. {
  36. @$createFile = fopen($fileName, "w") or die ("Can't create file ".$fileName."");
  37. fwrite ($createFile,"",0);
  38. @chmod($fileName, 0666);
  39. fclose($createFile);
  40. }
  41. @$openFile = fopen($fileName,"w+") or die ("Access is denied. Set permission to ".$fileName." by command in console \"chmod 666 ".$fileName."\"");
  42. if ($openFile && flock($openFile,LOCK_EX)) {
  43. @fwrite($openFile,$fileData);
  44. }
  45. fclose($openFile);
  46. }
  47.  
  48. function createFile($fileName)
  49. {
  50. if(!file_exists($fileName))
  51. {
  52. @$createFile = fopen($fileName, "w") or die ("Can't create file ".$fileName."");
  53. fwrite ($createFile,"",0);
  54. @chmod($fileName, 0666);
  55. fclose($createFile);
  56. }
  57. }
  58.  
  59. function convertLink($content)
  60. {
  61. global $constant;
  62. $content = preg_replace('/(http|ftp|news|https)(:\/\/)([^<> ])+/i', "<a href='\\0' class='messagelink'>\\0</a>", $content);
  63. $content = preg_replace('/([\w-?&;#~=\.\/]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?))/i', "<a href='mailto:\\1'>\\1</a>", $content);
  64. return $content;
  65. }
  66.  
  67. function divideWord($content,$maxWordLength = "30")
  68. {
  69. return wordwrap($content, $maxWordLength, " ", 1);
  70. }
  71.  
  72.  
  73. $back = "$HTTP_REFERER";
  74. $time = date("d M, Y - H:i");
  75. //############
  76. //start of the script for adding
  77. //############
  78. if($action){
  79. if($name){
  80. if($comment){
  81.  
  82. $id = date("dMYHis");
  83.  
  84. if (file_exists("${file}"))
  85. include("${file}");
  86. else
  87. createFile("${file}");
  88.  
  89. $comment = ereg_replace("[ ]{2,}", " ", $comment);
  90. $comment = convertLink($comment);
  91. $comment = str_replace("\"", "&quot;", $comment);
  92. $comment = str_replace("\n", " <br/>", $comment);
  93. $comment = str_replace("\$", " $", $comment);
  94. $comment = strip_tags($comment, '');
  95. if($img){
  96. $comment = str_replace("[img=", "<img src='", $comment);
  97. $comment = str_replace("][/img]", "'>", $comment);
  98. }
  99. $comment = trim($comment);
  100. $comment = stripslashes($comment);
  101.  
  102.  
  103. $cnt = 0;
  104. $addContent = "<?php\n";
  105.  
  106. $addContent .= "\t\$content[0]['page'] = \"".$page."\";\n";
  107. $addContent .= "\t\$content[0]['delete'] = \"".$id."\";\n";
  108. $addContent .= "\t\$content[0]['name'] = \"".$name."\";\n";
  109. $addContent .= "\t\$content[0]['comment'] = \"".$comment."\";\n";
  110. $addContent .= "\t\$content[0]['time'] = \"".$time."\";\n";
  111.  
  112.  
  113.  
  114. $contentCnt = sizeof($content);
  115. if ($contentCnt != 0)
  116. $addContent .= "\n";
  117. for($i = 0; $i < $contentCnt; $i++)
  118. {
  119. $cnt++;
  120. while(list($key, $value) = each($content[$i]))
  121. {
  122. $addContent .= "\t\$content[".$cnt."]['".$key."'] = \"".$value."\";\n";
  123. }
  124. if ($i != $contentCnt-1)
  125. $addContent .= "\n";
  126. }
  127. $addContent .= "?>";
  128. reWriteDataInFile ($addContent, "$file");
  129.  
  130.  
  131.  
  132.  
  133.  
  134. }}
  135. header ("location: $back");
  136. //#############
  137. //end of script for adding
  138. //#############
  139. //show the entry form if nothing has been added
  140. //#############
  141. $page = "${HTTP_HOST}${PHP_SELF}";
  142. if (file_exists("${path}${file}"))
  143. include("${path}${file}");
  144.  
  145. print<<<END
  146. <p><b><font size="3" face="Verdana, Arial, Helvetica, sans-serif">Wpisz swoją opinię</font></b><br><font size="1" face="verdana">napisz czy Ci się udało, co by zmienić na stronie?</font></p>
  147. <form action="${address}talkback.php" name="f" method="post">
  148.   <table width="500" border="0" cellspacing="0" cellpadding="0">
  149.   <tr>
  150.   <td width="64">
  151.   <div align="right"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Imię:</font></b></div>
  152.   </td>
  153.   <td width="436"><b><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><font color="#000000">
  154.   <input type="text" maxlength="40" name="name" style="width: 300;font-size: 7pt; font-family: Arial; background-color: #FFFFFF; color: black; border: 1 solid #000000" size="10">
  155.   </font></font></b></td>
  156.   </tr>
  157.   <tr>
  158.   <td width="64" valign="top"> <script language="Javascript">
  159. function help(){
  160. alert("INFORMATION\\n\\n Images are $imgnfo\\n\\n");
  161. }
  162. </script>
  163.   <div align="right"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Komentarz:</font></b></div><div align="center"><font face="verdana" size="1"> <a href="java script:help()"><font color="blue">help</font></a></font></div>
  164.   </td>
  165.   <td width="436"><b><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><font color="#000000">
  166.   <textarea name="comment" style="width: 300;font-size: 7pt; font-family: Arial; background-color: #FFFFFF; color: black; border: 1 solid #000000" cols="10" rows="4"></textarea>
  167.   </font></font></b></td>
  168.   </tr>
  169.   <tr>
  170.   <td width="64">
  171.   <div align="right"><font face="Verdana, Arial, Helvetica, sans-serif"><font face="Verdana, Arial, Helvetica, sans-serif"><font size="2"><font size="2"><b></b></font></font></font></font></div>
  172.   </td>
  173.   <td width="436"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
  174.   <input type="submit" name="Submit" value="Wyślij" style="width: 300;font-size: 7pt;" ><input type="hidden" name="action" value="yeah_baby"><input type="hidden" name="page" value="$page">
  175.   </font></b></td>
  176.   </tr>
  177.   </table>
  178. </form>
  179.  
  180. END;
  181.  
  182.  
  183.  
  184. ?></div>
  185. <div style="text-align: center"></font></font><br>
  186. <table width="500" border="0" cellspacing="0" cellpadding="0"></div>
  187. <?
  188. $now = "${HTTP_HOST}${PHP_SELF}";
  189.  
  190.  
  191. $currentContent = $content;
  192. for ($i = 0; $i < sizeof($currentContent); $i++)
  193. {
  194. $try = $currentContent[$i]['page'];
  195. $message = $currentContent[$i]['comment'];
  196. $message = str_replace("java script:", "[talkback JS filter]", $message);
  197. if($try == $now){
  198. ?>
  199. <div style="text-align: center"> <tr>
  200. <td bgcolor="<?echo $title_colour;?>"><font face="Verdana, Arial, Helvetica, sans-serif"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><font color='navy'><font color='black'>
  201. <font size="2" color="#FFFFFF"> <b>
  202. <?=$currentContent[$i]['name']?>
  203. </b></font></font></font></font><b><font size="2" color="#FFFFFF">commented
  204. at </font></b></font><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#FFFFFF">
  205. <?=$currentContent[$i]['time']?>
  206. </font></b><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><font color='navy'><font color='black'>
  207. </font></font></font></td>
  208. </tr>
  209. <tr>
  210. <td bgcolor="<?echo $message_colour;?>"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><font color='navy'><font color='black'>
  211. &nbsp;<?=$message?>&nbsp;
  212. </font></font></font></td>
  213. </tr><?}}?>
  214. </table></div>
  215. <p align="center"><font face="Verdana, Arial, Helvetica, sans-serif" color="blue" size="1">
  216.  
  217. </font></p>
  218. [php]


Do pliku comment.dat nie zapisuje nic, i nie pojawia sie nowy komentarz na stronce sad.gif
Prosze mi cos doradzic ?
Otto
Ja bym radził znaleźć jakiś system komentarzy z wykorzystaniem bazy danych anie dokumentów tekstowych...
CuteOne
Pliki są fajne jeżeli się wie jak ich używać. Co do Twojego "problemu" stwórz nowy plik np. comments.php i wpisz do niego:

  1.  
  2. $action = (!empty($_POST['action'])) ? $_POST['action'] : '';
  3. $name = (!empty($_POST['name'])) ? $_POST['name'] : '';
  4. $comment = (!empty($_POST['comment'])) ? $_POST['comment'] : '';
  5. $page = $_POST['page'];
  6.  
  7. require 'talkback.php';
  8.  
wowo
Dzieki za odpowiedź.

Ale nadal jest to samo sad.gif po wpisaniu czegos stronka sie przełąduje ale nic nowego nie wyskakuje sad.gif
Niestety taki dobry w php nie jestem żeby samemu znaleźć bląd w kodzie .
CuteOne
Zmień to na coś porządnego czytaj nowego.. a brak wpisu był wywołany przez action="" w <form>

podmień to:
  1. <form action="${address}talkback.php" name="f" method="post">

na to:
  1. <form action="" name="f" method="post">


i to:
  1. $back = "$HTTP_REFERER";

na to:
  1. $back = "comments.php"; //lub jeżeli includujesz comments przez index to np. index.php?strona=comments


Odpalasz wszystko przez plik comments.php
wowo
Kurcze nie dziala dalej sad.gif /Cannot modify header information - headers already sent / line 155 - taki blad wyskakuje po wyslaniu komentarza.

A jak mówisz ze to jest do du.., to doradz jakis prosty skrypt, bo probowalem z netu wiele i albo sa trudne, albo nic mi nie dziala.

Nie wiem co jest zgrane.

Dzięki za pomoc.
CuteOne
do comments.php na początku skryptu zaraz za <?php dodaj ob_start(); a na konieć tuż przed ?> ob_end_flush();
wowo
smile.gif Juz dodaje do comment.dat wpisy i nie ma juz tego bledu smile.gif

Tylko na stronce sie nic nie pojawia, nie publikuje tego wpisu, to pewnie jeszcze jakis blachy blad.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.