[PHP] System newsow problem

Języki, których efekty są wykonywane po stronie serwera. PHP, ASP czy CGI w połączeniu z bazami danych SQL dają niezwykłe możliwości budowy i zarządzania stron WWW. Tu zadajemy pytania oraz demonstrujemy kod, z którym mamy problem.
Cotter
Nowy
Nowy
Posty: 69
Rejestracja: pn lut 06, 2006 3:11 pm

Re: [PHP] System newsow problem

Post autor: Cotter »

[php]<?php
<?php

if ($haslo != "haslo")
{
print "Złe hasło";
die();
}

$old_comments = file("$comm_file");
$new_comments = fopen("$comm_file", "w");
@flock ($new_comments,2);

$found = FALSE;
foreach($old_comments as $old_comments_line)
{
$old_comments_arr = explode("|>|", $old_comments_line);
if($old_comments_arr[0] == $id)
{
$old_comments_arr[1] = trim($old_comments_arr[1]);
fwrite($new_comments,
"$old_comments_arr[0]|>|$old_comments_arr[1]$time|$name|$mail|$ip|$comments||
\n");
$found = TRUE;
}else{
fwrite($new_comments, $old_comments_line);
//if we do not have the news ID in the comments.txt we are not doing anything
(see comment below) (must make sure the news ID is valid)
}
}
if(!$found){
/* // do not add comment if News ID is not found \\ fwrite($new_comments,
"$id|>|$time|$name|$mail|$ip|$comments||\n");*/

echo("<div style=\"text-align: center;\">CuteNews did not added your
comment because there is some problem with the comments database.<br
/><a href=\"javascript:history.go(-1)\">go back</a></div>");
$CN_HALT = TRUE;
break 1;
}
@flock ($new_comments,3);
fclose($new_comments);
?>[/php]

Najprostrze z rozwiązań. Wypisze, że podano złe hasło, po czym zakończy swoje działanie.
ODPOWIEDZ