Witam,
Próbuję dokonać modyfikacji systemu newsów PSNews 1.3, tak, aby obok komentarzy wyświetlał się nr IP i Host osoby komentującej. Niestety nie znam PHP a obecny efekt końcowy jest taki, że obok wszystkich komentarzy wyświetla się IP i Host, tyle tylko, że mój, a nie użytkowników ...Jak powiązać zmienne odpowiadające za ip oraz host z komenatrzami, by nastąpiło zróżnicowanie? Poniżej zamieszczam kod pliku show.php
  1. if(eregi("://", $newspath)){
  2. die("Nieautoryzowany dostęp!");
  3. }
  4. if(!isset($newspath)){
  5. $newspath = "news";
  6. }
  7. include("$newspath/functions.php");
  8. $config = confload($newspath);
  9.  
  10. $userlist_f = file("$newspath/users.inc.php");
  11. unset($userlist_f[0]);
  12. unset($userlist_f[count($userlist_f)]);
  13. reset($userlist_f);
  14. while((list($key, $val) = each($userlist_f))&&($logged!="true")){
  15. $expl = explode("||", $val);
  16. $userlist[$expl[0]] = $expl;
  17. }
  18.  
  19. function news_wiadomosc($wiadomosc){
  20. global $config;
  21. global $newspath;
  22. return tplparse(array('{WIADOMOSC}'),array($wiadomosc),$config["template"],$newspath,"wiadomosc.html");
  23. }
  24. switch($_GET["function"]){
  25.  
  26. default:
  27. $_GET['no']=intval($_GET['no']);
  28. $newsfile = file("$newspath/news.txt");
  29. $count = count($newsfile);
  30. if($config["stronicownie"] != "off"){
  31. if(!isset($_GET["npage"])){ $npage = "1"; }
  32. else{ $npage = $_GET["npage"]; }
  33. $ilestron = $count/$config["stronicowanie"];
  34. $ilestron = ceil($ilestron);
  35. $begin = $count - $config["stronicowanie"]*($npage-1);
  36. if($begin>$count){ $begin = $count; }
  37. $end = $begin - $config["stronicowanie"];
  38. if($end<0){ $end = 0; }
  39. }
  40. else{
  41. $begin = $count;
  42. $end = 0;
  43. }
  44. for($i=$begin-1; $i>=$end;$i--){
  45. $news = explode("||", $newsfile[$i]);
  46. if($config["skracanie"] != "off"){
  47. $news[2] = ps_substr($news[2], $config["skracanie"], "... [<a href=\"".$config["adres"]."function=show_all&no=$news[0]\">więcej</a>]");
  48. }
  49. $news[2] = pscode($news[2]);
  50. if($config["emoty_news"] == "tak"){
  51. $news[2] = emots($news[2], $newspath);
  52. }
  53. $news[2] = stripslashes($news[2]);
  54. $news[2] = preg_replace("'\\|\\|'s", "||", $news[2]);
  55.  
  56. $news[1] = stripslashes($news[1]);
  57. $news[1] = preg_replace("'\\|\\|'s", "||", $news[1]);
  58.  
  59. //$news[1] = wordwrap($news[1], 50, " ", 1);
  60. //$news[2] = wordwrap($news[2], 50, " ", 1);
  61.  
  62.  
  63. $data = date("d.m.Y, H:i", $news[3]);
  64.  
  65. if($config["nimgs"]=="tak"){
  66. $img_path = "$newspath/nimgs/$news[5]";
  67. if((file_exists($img_path))&&($news[5]!="brak")&&($news[5]!="")){
  68. $news[2] = "<img src=\"$img_path\" align=\"".$config["nimgs_align"]."\" border=0> ".$news[2];
  69. }
  70. }
  71.  
  72. if(file_exists("$newspath/komentarze/$news[0]")){
  73. $komfile = @file("$newspath/komentarze/$news[0]");
  74. $ilekomentarzy = count($komfile);
  75. }
  76. else{ $ilekomentarzy = 0; }
  77.  
  78. $print_center.= tplparse(array('{TYTUL}','{NEWS}','{AUTOR}','{EMAIL}','{DATA}','{KOMENTARZE}','{ILEKOMENTARZY}'),array($news[1],$news[2],
  79.  
  80. $userlist[$news[4]][3],$userlist[$news[4]][4],$data,$config["adres"]."function=show_all&no=$news[0]",$ilekomentarzy),$config["template"],$newspath,"news.html");
  81. }
  82. if($config["stronicownie"] != "off"){
  83. $print_center.= "<br><center>";
  84. if($npage>1){ $prevp = $npage-1; $print_center.= "<a href=\"".$config["adres"]."npage=$prevp\"><<</a>"; }
  85. else{ $print_center.= "<<"; }
  86. $print_center.= " $npage z $ilestron ";
  87. if($npage<$ilestron){ $nextp = $npage+1; $print_center.= "<a href=\"". $config["adres"] ."npage=$nextp\">>></a>"; }
  88. else{ $print_center.= ">>"; }
  89. $print_center.= "</center><br>";
  90. }
  91. break;
  92.  
  93. /* CAŁOŚĆ NEWSA + KOMENTARZE */
  94. case show_all:
  95. $_GET['no']=intval($_GET['no']);
  96. $newsfile = file("$newspath/news.txt");
  97. reset($newsfile);
  98. foreach($newsfile as $news){
  99. $news = explode("||", $news);
  100. if($news[0] == $_GET["no"]){
  101. $news[2] = pscode($news[2]);
  102. if($config["emoty_news"] == "tak"){
  103. $news[2] = emots($news[2], $newspath);
  104. }
  105. $news[2] = stripslashes($news[2]);
  106. $news[2] = preg_replace("'\\|\\|'s", "||", $news[2]);
  107.  
  108. $news[1] = stripslashes($news[1]);
  109. $news[1] = preg_replace("'\\|\\|'s", "||", $news[1]);
  110.  
  111. //$news[1] = wordwrap($news[1], 50, " ", 1);
  112. //$news[2] = wordwrap($news[2], 50, " ", 1);
  113.  
  114. $data = date("d.m.Y, H:i", $news[3]);
  115.  
  116. if($config["nimgs"]=="tak"){
  117. $img_path = "$newspath/nimgs/$news[5]";
  118. if((file_exists($img_path))&&($news[5]!="brak")&&($news[5]!="")){
  119. $news[2] = "<img src=\"$img_path\" align=\"".$config["nimgs_align"]."\" border=0> ".$news[2];
  120. }
  121. }
  122.  
  123. if(file_exists("$newspath/komentarze/$news[0]")){
  124. $komfile = file("$newspath/komentarze/$news[0]");
  125. $ilekomentarzy = count($komfile);
  126. }
  127. else{ $ilekomentarzy = 0; }
  128.  
  129. $print_center.= tplparse(array('{TYTUL}','{NEWS}','{AUTOR}','{EMAIL}','{DATA}','{KOMENTARZE}','{ILEKOMENTARZY}'),array($news[1],$news
  130.  
  131. [2],$userlist[$news[4]][3],$userlist[$news[4]][4],$data,$config["adres"]."function=show_all&no=$news[0]",$ilekomentarzy),$config["template"],$newspath,"news.html");
  132. }
  133. }
  134. $print_center.= "<center>[<a href=\"". $config["adres"] ."function=add_kom&no=". $_GET["no"] ."\">skomentuj</a>] [<a href=\"". $config["adres"]
  135.  
  136. ."\">wróć do newsów</a>]</center><br>";
  137.  
  138. if($ilekomentarzy<1){ $print_center.= news_wiadomosc("Do tego newsa nie dodano jeszcze żadnego komentarza.<br>[<a href=\"".$config
  139.  
  140. ["adres"]."function=add_kom&no=".$_GET["no"]."\">skomentuj</a>]"); }
  141. else{
  142. reset($komfile);
  143. foreach($komfile as $kom){
  144. $kom = explode("||", $kom);
  145. if($config["emoty_kom"] == "tak"){
  146. $kom[1] = emots($kom[1], $newspath);
  147. }
  148. $kom[2] = stripslashes($kom[2]);
  149. $kom[2] = preg_replace("'\\|\\|'s", "||", $kom[2]);
  150.  
  151.  
  152. $kom[1] = stripslashes($kom[1]);
  153. $kom[1] = preg_replace("'\\|\\|'s", "||", $kom[1]);
  154.  
  155. $kom[1] = wordwrap($kom[1], 50, " ", 1);
  156. $kom[2] = wordwrap($kom[2], 50, " ", 1);
  157.  
  158. $data = date("d.m.Y, H:i", $kom[4]);
  159. $ip = $_SERVER['REMOTE_ADDR'];
  160. $host = gethostbyaddr($_SERVER['REMOTE_ADDR']);
  161.  
  162. $print_center.= tplparse(array('{KOMENTARZ}','{AUTOR}','{EMAIL}','{DATA}','{IP}','{HOST}'),array($kom[1],$kom[2],$kom[3],$data,$ip,
  163.  
  164. $host),$config["template"],$newspath,"komentarz.html");
  165. }
  166. }
  167.  
  168. break;
  169.  
  170. /* DODAWANIE KOMENTARZA */
  171. case add_kom:
  172. $_GET['no']=intval($_GET['no']);
  173. $banfile = file("$newspath/ban.txt");
  174. $ip = $_SERVER["REMOTE_ADDR"];
  175. $ban = "false";
  176. foreach($banfile as $linia){
  177. $linia = explode("||", $linia);
  178. if($linia[0] == $ip){ $ban = "true"; }
  179. }
  180. if($ban == "true"){
  181. $print_center = news_wiadomosc("Przepraszamy, ale nie masz zezwolenia na dodanie komentarza, ponieważ twoje IP ($ip) zostało zablokowane przez
  182.  
  183. administratora.<br>[<a href=\"".$config["adres"]."\">wróć do newsów</a>]");
  184. }
  185. else{
  186. if($_GET["do"] == "save"){
  187. if($_POST['kom_autor']=="" || $_POST['komentarz']==""){
  188. $print_center = news_wiadomosc("Wypełnij wszystkie wymagane pola!<br>[<a href=\"java script:history.back()\">wróć</a>]");
  189. }
  190. else{
  191. $filename = "$newspath/komentarze/".$_GET["no"];
  192. if(file_exists($filename)){
  193. $kom_autor = $_POST["kom_autor"];
  194. $kom_email = $_POST["kom_email"];
  195. $komentarz = $_POST["komentarz"];
  196. $kom_autor = strip_tags($kom_autor);
  197. $kom_email = strip_tags($kom_email);
  198. $komentarz = strip_tags($komentarz);
  199. $kom_autor = str_replace("|", "\\|", $kom_autor);
  200. $kom_email = str_replace("|", "\\|", $kom_email);
  201. $komentarz = str_replace("|", "\\|", $komentarz);
  202. $kom_autor = preg_replace("'\n|\r\n|\r'si", "", $kom_autor);
  203. $kom_email = preg_replace("'\n|\r\n|\r'si", "", $kom_email);
  204. $komentarz = preg_replace("'\n|\r\n|\r'si", "<br>", $komentarz);
  205. $numer = max_l_plik(0, "||", $filename)+1;
  206.  
  207. $file = fopen($filename, "a+");
  208. flock($file, 2);
  209. $puts = "$numer||$komentarz||$kom_autor||$kom_email||".time()."||$ip||\n";
  210. fputs($file, $puts);
  211. flock($file, 3);
  212. fclose($file);
  213. $print_center = news_wiadomosc("Twój komentarz został dodany.<br>[<a href=".$config["adres"].">wróć do newsów</a>]");
  214. }
  215. else{
  216. $print_center = news_wiadomosc("Nie można dodać komentarza - brak pliku z bazą danych do tego newsa.<br>[<a href=".
  217.  
  218. $config["adres"].">wróć do newsów</a>]");
  219. }
  220. }
  221. }
  222. else{
  223. $print_center.= "
  224. <form action=\"". $config["adres"]."function=add_kom&no=".$_GET["no"]."&do=save\" method=post name=formularz>
  225. *Autor:<br><input type=text name=\"kom_autor\"><br>
  226. Email:<br><input type=text name=\"kom_email\"><br>
  227. *Komentarz:<br>";
  228. if($config["emoty_kom"] == "tak"){ $print_center.= list_emots($newspath,"komentarz")."<br>"; }
  229. $print_center.= "<textarea style=\"width:300; height:150\" name=\"komentarz\"></textarea>
  230. <br>* - pola wymagane<br><br>
  231. <input type=submit value=\"dodaj\">
  232. <br><a href=\"".$config["adres"]."\">[rezygnuj]</a>
  233. </form>
  234. ";
  235. }
  236. }
  237. break;
  238. }

Dodam jeszcze, że ingerowałem w ten fragment (dodając zmienne ip oraz host)
  1. $ip = $_SERVER['REMOTE_ADDR'];
  2. $host = gethostbyaddr($_SERVER['REMOTE_ADDR']);
  3. $print_center.=tplparse(array('{KOMENTARZ}','{AUTOR}','{EMAIL}','{DATA}','{IP}','{HOST}'),array($kom[1],$kom[2],$kom[3],$data,$ip,$host),$config["template"],$newspath,"komentarz.html");

Z góry dziękuję za pomoc!
Próbowałem zmienić nazwę zmiennych dla $kom, jednak nadal wyświetla się wyłącznie moje IP. Pomoże ktoś? Wiem że dla Was to banalna sprawa...