[PHP][Pliki] Księga Gości v0.02

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.
Chmura
Przelotem
Przelotem
Posty: 220
Rejestracja: ndz gru 31, 2006 12:46 am
Lokalizacja: o stamtąd
Kontakt:

[PHP][Pliki] Księga Gości v0.02

Post autor: Chmura »

Witam
przedstawiam wam księgę gości opartą o pliki
chciałbym abyście ją ocenili i skomentowali (poradzili co zmienić, usunąć)

Plik admin.php :

[php]<?php
include('sprawdz.php');
ob_start();
function filtr_edit($co){
$co = str_replace("||","||",$co);
$co = str_replace("<br>", "", $co);
$co = str_replace("<br />", "", $co);
$co = str_replace("\n","<br />",$co);
return $co;
}
//funkcje pomocnicze//////////////////////////
$docel = 'baza_ksiega.txt';
$plik = file($docel);
$max = 4;
$ile = count($plik);
$ile_stron = ceil($ile/$max);
$plik_ban = "ban.txt";
$dodajban = $_GET['dodajban'];
$page = filtr_edit($_GET['page']);
$edit = filtr_edit($_GET['edit']);
$edit_nr = filtr_edit($_GET['ktora']);
$zapis = filtr_edit($_GET['zapis']);
$delete = filtr_edit($_GET['delete']);
$wyloguj = filtr_edit($_GET['wyloguj']);
$delete_usr = filtr_edit($_GET['delete_usr']);
$delete_ban = filtr_edit($_GET['delete_ban']);
$edit_mail = filtr_edit($_POST['edit_mail']);
$edit_nick = filtr_edit($_POST['edit_nick']);
$edit_data = filtr_edit($_POST['edit_data']);
$edit_ip = filtr_edit($_POST['edit_ip']);
$edit_tresc = filtr_edit($_POST['edit_tresc']);
$edit_www = filtr_edit($_POST['edit_www']);
$edit_gg = filtr_edit($_POST['edit_gg']);
$new_usr = filtr_edit($_GET['new_usr']);
$nick_usr = filtr_edit($_POST['nick_usr']);
$pass_usr = filtr_edit($_POST['pass_usr']);
$pass_usr_p = filtr_edit($_POST['pass_usr_p']);
$mail_usr = filtr_edit($_POST['mail_usr']);
$nrip = $_POST['nrip'];
$kolor1 = 'E8E2DD';
$kolor2 = 'E1DACE';
//////////////////////////////////////////////

?>
<html>

<head>
<meta http-equiv="Content-Language" content="pl">
<title> Panel Administracyjny</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<meta http-equiv="Content-Language" content="pl">
</head>
<link href="gfx/style.css" type="text/css" rel="stylesheet">

<body bgcolor="#FFFFFF">

<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="79%">
<tr>
<td>
<img border="0" src="gfx/admin/admin_03.jpg" width="213" height="139" alt=""></td>
<td>
<img border="0" src="gfx/admin/admin_04.jpg" width="203" height="139" alt=""></td>
<td>
<img border="0" src="gfx/admin/admin_05.jpg" width="202" height="139" alt=""></td>
<td>
<img border="0" src="gfx/admin/admin_06.jpg" width="198" height="139" alt=""></td>
</tr>
<tr>
<td width="213">
<img border="0" src="gfx/admin/admin_08.jpg" width="10" height="31" alt=""><a href="admin.php?page=0"><img border="0" src="gfx/admin/admin_09.jpg" width="190" height="31" alt=""></a></td>
<td width="203"><a href="admin.php?new_usr=new_usr">
<img border="0" src="gfx/admin/admin_11.jpg" width="189" height="31" alt=""></a></td>
<td width="202"><a href="admin.php?dodajban=form">
<img border="0" src="gfx/admin/admin_13.jpg" width="188" height="31" alt=""></a></td>
<td width="198"><a href="admin.php?wyloguj=wyloguj">
<img border="0" border="0" src="gfx/admin/admin_15.jpg" width="188" height="31" alt=""></a><img border="0" src="gfx/admin/admin_16.jpg" width="10" height="31" alt=""></td>
</tr>
<tr valign="top">
<td colspan="4" background="gfx/admin/admin_19.jpg" height="38">
<table class="main" border="0" width="100%" id="table1" cellspacing="0" cellpadding="0">
<tr>
<td width="14"> </td>
<td> </td>
</tr>
<tr>
<td width="14"> </td>
<td>
<div align="center">
<?php
if($wyloguj == 'wyloguj') {
unset($HTTP_SESSION_VARS['login']);
unset($HTTP_SESSION_VARS['haslo']);
session_destroy();
echo '<b>Zostałes wylogowany</b><br />';
echo '<a href="login.php">Zaloguj się</a>';
exit();
}
$dane_usr = file($plik_usr);
if($new_usr == "new_usr") {

$ile_usr = count($dane_usr);
echo '<b>Lista Usr\'ów [</b>'.$ile_usr.'<b>]:</b><br /><br />
<table class="main" border="0" width="300" id="table1" cellspacing="3" cellpadding="2">';
$i = (-1);
foreach($dane_usr as $linia) {

$i++;
$dana_usr = explode(" || ", $linia);

$kolor = $kolor1;
$kol++;
if($kol == 2) {
$kolor = $kolor2;
$kol = 0;
}

echo '<tr bgcolor="#'.$kolor.'" >
<td width="25"> '.$dana_usr[0].'</td>
<td width="200"> <a href="mailto:'.$dana_usr[3].'"><b>'.$dana_usr[1].'</a></b></td>
<td width="30"><a href="?delete_usr='.$i.'">Usun</a></td>
</tr>';
}
echo '</table><br /><br />';

echo'<b>Dodaj Usr\'a:</b><br /><br />
<form name="new_usr" method="post" action="admin.php?new_usr=dodaj">
<table class="main" width="300" border="0" cellspacing="0" cellpadding="0">
<tr>

<td>Nick:</td>
<td><input name="nick_usr" type="text" /></td>
</tr>
<tr>
<td>Hasło:</td>
<td><input name="pass_usr" type="text" /></td>
</tr>
<tr>
<td>Powtórz hasło:</td>
<td><input name="pass_usr_p" type="text" /></td>
</tr>
<tr>
<td>E-mail:</td>
<td><input name="mail_usr" type="text" /></td>


</tr>
</table>
<br>
<input type="submit" name="Submit" value="Dodaj" />
<input type="Reset" name="Reset" value="Wyczy¶ć" />
</form>';

exit();
}

if($new_usr == "dodaj") {
$check_usr = file($plik_usr);
foreach($check_usr as $linia) {
$dana = explode(" || ", $linia);
if($nick_usr == $dana[1]) {
exit('Ten Login jest już zajęty!');
}
}
if(empty($nick_usr)) {
exit('Nie wpisałes Loginu!');
}
if(empty($mail_usr)) {
exit('Nie wpisałes Maila!');
}
if(empty($pass_usr)) {
exit('Nie wpisałes hasla!');
}
if(empty($pass_usr_p)) {
exit('Nie powtórzyłes hasła!');
}
if($pass_usr != $pass_usr_p) {
exit('Podane hasła różnią się od siebie!');
}
$id_Nusr = file($plik_usr);
$i_usr = count($id_Nusr);
while($i <= 0) {
$id_usr = explode(' || ',$id_Nusr[$i_usr-1]);
$id_usr[0]++;
$i++;
}
$usr = ''.$id_usr[0].' || '.$nick_usr.' || '.$pass_usr.' || '.$mail_usr.' || '."\n";
$file_usr = fopen($plik_usr,"a+");
fputs($file_usr, $usr);
fclose($file_usr);
exit('Dodałe¶ użytkownika:'.$nick_usr.'');
}

if($delete_usr != "") {
unset($dane_usr[$delete_usr]);
$open = fopen($plik_usr, 'w');
foreach($dane_usr as $linia) {
fputs($open, $linia);
}
fclose($open);
exit('Skasowałes Usr\'a o ID '.$delete_usr.'</b><br />
Wróć do <a href="admin.php">Panelu Administracyjnego</a>');
}

if(!file_exists($plik_ban)) {
exit('Plik '.$plik_ban.' nie istnieje!');
}
$dane_ban = file($plik_ban);
if($dodajban == "form") {

echo '<table class="main" border="0" width="273" id="table1" cellspacing="3" cellpadding="2">';

$i = (-1);
foreach($dane_ban as $linia) {
$i++;
$dana_ban = explode(" || ", $linia);

$kolor = $kolor1;
$kol++;
if($kol == 2) {
$kolor = $kolor2;
$kol = 0;
}
echo '<tr bgcolor="#'.$kolor.'" >
<td width="34">'.$dana_ban[0].'</td>
<td width="188">'.$dana_ban[1].'</td>
<td width="27"><a href="?delete_ban='.$i.'">Usun</a></td>
</tr>';
}
echo '</table><br /><br />';

echo'<form name="dodajban" method="post" action="admin.php?dodajban=tak">
<table class="main" width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Wpisz IP do zbanowania</td>
<td><input name="nrip" type="text" /></td>
</tr>
</table>
<br />
<input type="submit" name="Submit" value="Dodaj" />
<input type="Reset" name="Reset" value="Wyczy¶ć" />
</form>';

exit();
}
if($dodajban == "tak") {
$id_ban= file($plik_ban);
$i_ban = count($id_ban);
while($i <= 0) {
$id_ip = explode(' || ',$i_ban-1);
$id_ip[0]++;
$i++;
}
$ban = ''.$id_ip[0].' || '.$nrip.' || '."\n";
$file_ban = fopen($plik_ban,"a+");
fputs($file_ban, $ban);
fclose($file_ban);
exit('Zbanowałe¶ IP:'.$nrip.'');
}

if($delete_ban != "") {
unset($dane_ban[$delete_ban]);
$open = fopen($plik_ban, 'w');
foreach($dane_ban as $linia) {
fputs($open, $linia);
}
fclose($open);
exit('Skasowałes IP o ID '.$delete_ban.'</b><br />
Wróć do <a href="admin.php">Panelu Administracyjnego</a>');
}

if($delete != "") {
unset($plik[$delete]);
$open = fopen($docel, 'w');
foreach($plik as $linia) {
fputs($open, $linia);
}
fclose($open);
exit('Skasowałes wpis o ID '.$delete.'</b><br />
Wróć do <a href="admin.php">Panelu Administracyjnego</a>');
}

if ($zapis == 'zapis') {

$wpis_new = $edit_nr." || ".$edit_tresc." || ".$edit_nick." || ".$edit_gg." || ".$edit_mail." || ".$edit_www." || ".$edit_data." || ".$edit_ip." || "."\n";
$baza[1] = file($docel);
$baza[2] = fopen($docel, "w+");
flock($baza[2], 2);
foreach($baza[1] as $linia) {
$dane = explode(' || ',$linia);
if ($linia!="\n" && $linia!=""){
if ($dane[0] != $edit_nr) {
fwrite($baza[2], $linia);
}
else {
fwrite($baza[2], $wpis_new);
}
}
}
echo 'Zedytowałe¶ wpis o Nr.'.$edit_nr.'<br />'."\n";
echo 'Wróć do <a href="admin.php?page='.$page.'">Panelu Administracyjnego</a>'."\n";
flock($baza[2], 3);
exit();
}

if(empty($page)) $page = 0;

$tmp = $ile-($page*$max);
$i_max = $max;

if($tmp < $max) $i_max = $tmp;

for($i = 0; $i < $i_max; $i++) {

$dana = explode(" || ", $plik[$page*$max+$i]);
$nr = ($ile-($page*$max+$i));
$cnt_www = strlen($dana[5]);
$max_www = 20;
$dana[1] = wordwrap($dana[1], 57, " ", 1);

$kolor = $kolor1;
$kol++;
if($kol == 2) {
$kolor = $kolor2;
$kol = 0;
}

if($edit == "edytuj" && $nr == $edit_nr ) {
include('form_edit.php');
}
else {
include('form_wpis_admin.php');
}
}

for($st = 0; $st < $ile_stron; $st++) {
if($page == $st){
$strony .= '<b>'.($st+1).'</b>|'."\n";
}
else{
$strony .= '<b><a href="?page='.$st.'">'.($st+1).'</a></b> |'."\n";
}
}
?>

</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="4">
<img border="0" src="gfx/admin/admin_17.jpg" width="816" height="13" alt=""></td>
</tr>
</table>
</div>

</body>

</html>
[/php]

Plik blokowanie.php:

[php]<?php
$ban = file("ban.txt");
foreach($ban as $linia){
$bany = explode(' || ', $linia);

if($_SERVER['REMOTE_ADDR'] == $bany[2] OR $REMOTE_ADDR == $bany[2]) {
echo 'Zostałes zbanowny!';
}
unset($linia);
}
?>[/php]

Plik emoty.php (jeszcze nie przeedytowany jak 123456 proponował)


[php]
<?php
//podmieniamy emoty...
$tresc = str_replace(":*","<img src=gfx/emoty/cmok.gif />",$tresc);
$tresc = str_replace(";*","<img src=gfx/emoty/cmok.gif />",$tresc);
$tresc = str_replace(":co:","<img src=gfx/emoty/co.gif />",$tresc);
$tresc = str_replace(":co?:","<img src=gfx/emoty/co.gif />",$tresc);
$tresc = str_replace(":co jest:","<img src=gfx/emoty/co_jest.gif />",$tresc);
$tresc = str_replace(":co jest?:","<img src=gfx/emoty/co_jest.gif />",$tresc);
$tresc = str_replace(":devil:","<img src=gfx/emoty/diabelek.gif />",$tresc);
$tresc = str_replace(":głaszcze:","<img src=gfx/emoty/glaszcze.gif />",$tresc);
$tresc = str_replace(":glaszcze:","<img src=gfx/emoty/glaszcze.gif />",$tresc);
$tresc = str_replace(":hahaha:","<img src=gfx/emoty/hahaha.gif />",$tresc);
$tresc = str_replace(";P","<img src=gfx/emoty/jezyk1.gif />",$tresc);
$tresc = str_replace(";p","<img src=gfx/emoty/jezyk1.gif />",$tresc);
$tresc = str_replace(":jupi:","<img src=gfx/emoty/jupi.gif />",$tresc);
$tresc = str_replace(":]","<img src=gfx/emoty/krzywy.gif />",$tresc);
$tresc = str_replace(";]","<img src=gfx/emoty/krzywy.gif />",$tresc);
$tresc = str_replace(":wrr:","<img src=gfx/emoty/kwasny.gif />",$tresc);
$tresc = str_replace(":lol:","<img src=gfx/emoty/lol.gif />",$tresc);
$tresc = str_replace(":lol2:","<img src=gfx/emoty/lol2.gif />",$tresc);
$tresc = str_replace(":mruga","<img src=gfx/emoty/oczko.gif />",$tresc);
$tresc = str_replace(":papapa:","<img src=gfx/emoty/papa.gif />",$tresc);
$tresc = str_replace(";(","<img src=gfx/emoty/placze.gif />",$tresc);
$tresc = str_replace(":przytul:","<img src=gfx/emoty/przytul.gif />",$tresc);
$tresc = str_replace(":sciana:","<img src=gfx/emoty/sciana.gif />",$tresc);
$tresc = str_replace(":¶ciana:","<img src=gfx/emoty/sciana.gif />",$tresc);
$tresc = str_replace(":love:","<img src=gfx/emoty/serduszka2.gif />",$tresc);
$tresc = str_replace(":sex:","<img src=gfx/emoty/sex.gif />",$tresc);
$tresc = str_replace(":spoko:","<img src=gfx/emoty/spoko.gif />",$tresc);
$tresc = str_replace(":tańcze:","<img src=gfx/emoty/tancze.gif />",$tresc);
$tresc = str_replace(":tańczę:","<img src=gfx/emoty/tancze.gif />",$tresc);
$tresc = str_replace(":tancze:","<img src=gfx/emoty/tancze.gif />",$tresc);
$tresc = str_replace(":tanczę:","<img src=gfx/emoty/tancze.gif />",$tresc);
$tresc = str_replace(":tuptup:","<img src=gfx/emoty/tuptup.gif />",$tresc);
$tresc = str_replace(":wow:","<img src=gfx/emoty/wow.gif />",$tresc);
$tresc = str_replace(":|","<img src=gfx/emoty/ysz.gif />",$tresc);
$tresc = str_replace(";|","<img src=gfx/emoty/ysz.gif />",$tresc);
$tresc = str_replace(":wstydni¶:","<img src=gfx/emoty/zawstydzony.gif />",$tresc);
$tresc = str_replace(":wstydnis:","<img src=gfx/emoty/zawstydzony.gif />",$tresc);
$tresc = str_replace(":D","<img src=gfx/emoty/zeby.gif />",$tresc);
$tresc = str_replace(";D","<img src=gfx/emoty/zeby.gif />",$tresc);
$tresc = str_replace(":d","<img src=gfx/emoty/zeby.gif />",$tresc);
$tresc = str_replace(";d","<img src=gfx/emoty/zeby.gif />",$tresc);
$tresc = str_replace(":-)","<img src=gfx/emoty/oczko_na.gif />",$tresc);
$tresc = str_replace(":nenene","<img src=gfx/emoty/jezyk2.gif />",$tresc);
?>[/php]

plik form_edit.php:

[php]<?php

echo '

<form action="?page='.$page.'&zapis=zapis&ktora='.$dana[0].'" method="POST">
<table class="edit" border="0" width="482" id="table1" cellspacing="0" cellpadding="3" height="356">
<tr valign="top">
<td height="11" width="86"><b>Autor:</b></td>
<td height="11" width="108">
<input type="text" name="edit_nick" value="'.$dana[2].'" size="25"></td>
<td height="50" rowspan="4" width="400">
<p align="right"><b>
<b>Wpis nr.</b>'.$nr.'<b> o id.</b>'.$dana[0].' |
<a href="?page='.$page.'">anuluj</a> |
<a href="?page='.$page.'&delete='.($page*$max+$i).'">usuń</a></td>
</tr>
<tr valign="top">
<td height="7" width="86"><b>IP:</b> </td>
<td height="7" width="108">
<input type="text" name="edit_ip" value="'.$dana[7].'" size="25" readonly></td>
</tr>
<tr valign="top">
<td height="7" width="86"><b>Data:</b </td> </td>
<td height="7" width="108">
<input type="text" name="edit_data" value="'.$dana[6].'" size="25" readonly></td>
</tr>
<tr valign="top">
<td height="7" width="86"><b>E-mail:</b></td>
<td height="7" width="108">
<input type="text" name="edit_mail" value="'.$dana[4].'" size="25"></td>
</tr>
<tr valign="top">
<td height="7" width="86"><b>http://</b> </td>
<td height="7" width="108">
<input type="text" name="edit_www" value="'.$dana[5].'" size="25"></td>
</tr>
<tr valign="top">
<td height="7" width="86"><b>Gadu-gadu:</b></td>
<td height="7" width="108">
<input type="text" name="edit_gg" value="'.$dana[3].'" size="25"></td>
</tr>
<tr valign="top">
<td colspan="3"><br>
<table class="edit" border="0" width="100%" id="table2" cellspacing="0" cellpadding="0">
<tr>
<td width="26"></td>
<td><textarea name="edit_tresc" rows="20" cols="89">'.$dana[1].'</textarea><br>
<input type="submit" value="Zapisz" /></td>
</tr>
</table>
</td>
</tr>
</table>
</form>

';
?>[/php]

Plik form_wpis_admin.php:
[php]<?php

echo '<table class="main" border="0" width="470" id="table1" cellspacing="0" cellpadding="0" height="113">'."\n";
echo '<tr valign="top">'."\n";
echo '<td width="452">'."\n";
if($dana[4] != "Nie podano") {
echo '<b>Autor:</b> <a href="mailto:'.$dana[4].'">'.$dana[2].'</a> <b>Data:</b> '.$dana[6].'</td>'."\n";
}
else {
echo '<b>Autor:</b> '.$dana[2].' <b>Data:</b> '.$dana[6].'</td>'."\n";
}
echo '<td width="250" align="right">ID: '.$dana[0].' | <a href="?page='.$page.'&edit=edytuj&ktora='.$nr,'">edytuj</a> | <a href="?page='.$page.'&delete='.($page*$max+$i).'">usun</a> | ['.$nr.']</td>'."\n";
echo '</tr>'."\n";
echo '<tr valign="top">'."\n";
echo '<td colspan="2" bgcolor="#'.$kolor.'"><br />';
echo $dana[1];
echo '<br /><br /></td>'."\n";
echo '</tr>'."\n";
echo '<tr valign="top">'."\n";
echo '<td colspan="2">'."\n";


if($dana[5] != "Nie podano") { //jesli podano adres strony...
if( $cnt_www <= $max_www) { //jesli adres strony jest krótszy lub równy $max_ww...
echo '<b>http://</b> <a href="http://'.$dana[5].'">'.$dana[5].'</a> '."\n";
}
else { //jesli nie
$www_ciach = substr($dana[5], 0, $max_www); // wyświetlamy tylko $max_www jego nazwy
echo '<b>http://</b><a href="http://'.$dana[5].'">'.$www_ciach.'...</a> '."\n";
}
}

if($dana[3] != "Nie podano") { //jesli nie podano numeru gg
echo '<b>Gadu-gadu:</b> <a href="gg:'.$dana[3].'"> '.$dana[3].'<img src="http://www.gadu-gadu.pl/users/status.asp?id='.$dana[3].'" border="0" width="15" height="15" /></a>'."\n";
}


echo '</td>'."\n";
echo '</tr>'."\n";
echo '<tr valign="top">'."\n";
echo '<td colspan="2" height="12"></td>'."\n";
echo '</tr>'."\n";
echo '</table>'."\n";

?>[/php]

plik login.php:

[xml]<html>

<head>
<style type="text/css">
input.panel {
font-family: tahoma;
border: 1px solid #666666;
margin-top: 6;
font-size: 11px;
color: #9D9E9D;
background-color: #ffffff;
}
</style>
<title>PanelAdministracyjny - KsięgaGo¶ci Chmurav0.02</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
<meta http-equiv="Content-Language" content="pl" />
<meta name="http://chmura.go.pl" content="[email protected]" />
</head>

<body topmargin="30">

<div align="center">
<blockquote>
<table border="0" width="236" id="table1" cellspacing="0" cellpadding="0" height="71">
<tr>
<td>
<table border="0" width="100%" id="table2" cellspacing="0" cellpadding="0" height="163">
<tr>
<td height="82" background="gfx/log/tlo.jpg">
<table border="0" width="100%" id="table3" cellspacing="0" cellpadding="0"><form method="POST" action="admin.php">
<tr>
<td width="176" height="17"></td>
<td></td>
</tr>
<tr>
<td width="176" align="right">
<p align="center">

<input name="login" size="30" class="panel" style="float: right" /></td>
<td align="right">
<p align="center">
<input class="panel" type="checkbox" name="pam" value="1"></p>
</td>
</tr>
<tr>
<td width="176" align="right">
<p align="center">
<input name="pass" class="panel" size="30" type="password" style="float: right" /></p>
</td>
<td>
<p align="center">
<input class="panel" value="wejdz" type="submit" />
</form></p>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="21"><a href="http://www.chmura.go.pl">
<img border="0" src="gfx/log/odnosnik.jpg" width="236" height="20" /></a></td>
</tr>
<tr>
<td height="1"></td>
</tr>
<tr>
<td>
<img border="0" src="gfx/log/cien.jpg" width="236" height="52" /></td>
</tr>
</table>
</td>
</tr>
</table>
</blockquote>
</div>

</body>

</html>[/xml]

plik zapis.php:
[php]<?php

ob_start();
session_start();

function filtr($co){
$co = str_replace("||","||",$co);
$co = str_replace("<br>", "", $co);
$co = str_replace("<br />", "", $co);
$co = str_replace("\n","<br />",$co);
$co = strip_tags($co, '<p><br><i><u><b>');
return $co;
}
$plik = "baza_ksiega.txt";
$nick = filtr($_POST['nick']);
$mail = filtr($_POST['mail']);
$www = filtr($_POST['www']);
$kom_gg = filtr($_POST['kom_gg']);
$tresc = filtr($_POST['tresc']);
$emoty = $_POST['emoty'];
$data = date('H:i j.m.Y');
$cnt = count(file($plik));
$ip = $_SERVER['REMOTE_ADDR'];
$token = $_SESSION['ksiega_token'];
$token_f = filtr($_POST['ksiega_token']);

if($_COOKIE['ciacho_ksiega'] == 1) {
echo 'Dzi¶ już dodałe¶ jeden wpis';
exit();
}
if ( $token != $token_f) {
echo "Wprowadzono niepoprawny token!";
exit();
}
if((!$tresc) && (!$nick) && (!$kom_gg) && (!$mail) && (!$www)) {
echo 'Nie uzupełniłe¶ zadnego z pól!!';
exit();
}
if(!$tresc) {
echo 'Nie wpisałe¶ zadnej tre¶ci!';
exit();
}
if(!$nick) {
echo 'Nie wpisałe¶ Nicka!';
exit();
}
if(!$kom_gg) {
$kom_gg = 'Nie podano';
}
if(!$mail) {
$mail = 'Nie podano';
}
if(!$www) {
$www = 'Nie podano';
}
if($emoty != 1) {
include('emoty.php');
}
if(strstr($www, "http://")!==False) {
$www = substr($www , 7);
}
if(strstr($gg, "gg:")!==False) {
$gg = substr($gg , 3);
}


if(file_exists($plik)) {

$id_f = file($plik);
while($i <= 0) {
$id = explode(' || ',$id_f[0]);
$id[0]++;
$i++;
}
$wpis = ''.$id[0].' || '.$tresc.' || '.$nick.' || '.$kom_gg.' || '.$mail.' || '.$www.' || '.$data.' || '.$ip.' || '."\n";
$file = fopen($plik,"r+");
$wpis = $wpis. fread($file,filesize($plik));
rewind($file);
fputs($file,$wpis);
fclose($file);
setcookie("ciacho_ksiega", 1, time()+86400);
}
else {
echo 'Plik '.$plik.' nie istnieje!';
exit();
}
echo '<p>Gratulacje dodałe¶ wpis '.$nick.'!';
echo '<p><a href="ksiega.php">Zobacz swój wpis</a>';
echo '<p><a href="index.php">Wróć do strony głównej</a>';

?>[/php]

plik wpis.php :
[php]
<?php
ob_start();
session_start();

if($_COOKIE['ciacho_ksiega'] == 1) { // sprawdzamy ciacho
echo 'Dzi¶ już dodałe¶ jeden wpis :)'; // jesli ciacho jes...
exit();
}
$_SESSION['ksiega_token'] = ''; //przyisujemy pustke sessji

for($i=0;$i<5;$i++) { // pętla for określająca z ilu liczb będzie sie składał token
$liczba = rand(0,9); // losujemy liczbę
$_SESSION['ksiega_token'] .= $liczba; // przypisujemy liczby sessji
$img .= '<img src="gfx/token/'.$liczba.'.gif" >'; // zapisujemy wynik do zmiennej $img
}
?>
<!------------------------------------------------------->
<script language="javascript">
function onlydec(event,f)
{
if (event.srcElement) {kc = event.keyCode;} else {kc = event.which;}
if ((kc < 47 || kc > 57) && kc != 8 && kc != 0) return false;
return true;
}
</script>
<!------------------------------------------------------->
<script type="text/javascript">
function maxLength1(o,v,m){
document.getElementById(v).innerHTML=
((o.value=o.value.substr(0,m)).length);
}

function maxLength2(e,o,v,m){
// ponieważ Gecko zdarzenie onkeypress występuje
// także po naciśnięciu klawiszy nie alfanumerycznych
// (event.keyCode!=0), naciśnięcia takiego klawisza
// nie jest anulowane
if(!o.all&&e.keyCode!=0)return!0;
// anulowanie lub nie w zależności od liczby znaków
// z jednoczesnym odświerzeniem pola wyświetlającego
// liczbę znaków
return(document.getElementById(v).innerHTML=o.value.length)<m
}

function maxLength3(o,v,m){
if(o.value.length>m)
document.getElementById(v).innerHTML=
((o.value=o.value.substr(0,m)).length);
}

</script>
<!------------------------------------------------------->
<script type="text/javascript">
function emot(e){
document.formularz.tresc.value+=e;
document.formularz.tresc.focus();
}
</script>
<!------------------------------------------------------->
</head>
<form name="formularz" method="post" action="zapis.php">
<table id="table3" border="0" cellpadding="0" cellspacing="0" height="100" width="37%">
<tr valign="top">
<td align="right" width="4%">
<p align="right"><b>*Nick:</b></td>
<td width="27%"><input value="Imię lub Nick" onblur="if( this.value == '' ) this.value = 'Imię lub Nick';" onfocus="if( this.value == 'Imię lub Nick' ) this.value = '';" name="nick" maxlength="20"></td>
<td rowspan="6" width="41%">
<div align="center">
<table id="table4" border="0" cellpadding="0" cellspacing="0" width="12%">
<tr>
<td align="center">
<a href="javascript: emot(':co?:')"><img src="gfx/emoty/co.gif" border="0" height="25" width="17"></a></td>
<td align="center">
<a href="javascript: emot(':co jest?:')"><img src="gfx/emoty/co_jest.gif" border="0" height="15" width="15"></a></td>
<td align="center">
<a href="javascript: emot(':devil:')"><img src="gfx/emoty/diabelek.gif" border="0" height="20" width="15"></a></td>
<td align="center">
<a href="javascript: emot(':hahaha:')"><img src="gfx/emoty/hahaha.gif" border="0" height="27" width="29"></a></td>
</tr>
<tr>
<td align="center">
<a href="javascript: emot(':]')"><img src="gfx/emoty/krzywy.gif" border="0" height="15" width="15"></a></td>
<td align="center">
<a href="javascript: emot(':wrr:')"><img src="gfx/emoty/kwasny.gif" border="0" height="15" width="15"></a></td>
<td align="center">
<a href="javascript: emot(':lol2:')"><img src="gfx/emoty/lol2.gif" border="0" height="15" width="15"></a></td>
<td align="center">
<a href="javascript: emot(':lol:')"><img src="gfx/emoty/lol.gif" border="0" height="18" width="18"></a></td>
</tr>
<tr>
<td align="center">
<a href="javascript: emot(';(')"><img src="gfx/emoty/placze.gif" border="0" height="15" width="40"></a></td>
<td align="center">
<a href="javascript: emot(':sciana:')"><img src="gfx/emoty/sciana.gif" border="0" height="15" width="30"></a></td>
<td align="center">
<a href="javascript: emot(':love:')"><img src="gfx/emoty/serduszka2.gif" border="0" height="16" width="23"></a></td>
<td align="center">
<a href="javascript: emot(':sex:')"><img src="gfx/emoty/sex.gif" border="0" height="20" width="24"></a></td>
</tr>
<tr>
<td align="center">
<a href="javascript: emot(':wow:')"><img src="gfx/emoty/wow.gif" border="0" height="19" width="19"></a></td>
<td align="center">
<a href="javascript: emot(':|')"><img src="gfx/emoty/ysz.gif" border="0" height="15" width="15"></a></td>
<td align="center">
<a href="javascript: emot(':wstydnis:')"><img src="gfx/emoty/zawstydzony.gif" border="0" height="15" width="15"></a></td>
<td align="center">
<a href="javascript: emot(';D)"><img src="gfx/emoty/zeby.gif" border="0" height="15" width="15"></a></td>
</tr>
<tr>
<td align="center">
<a href="javascript: emot(':jupi:')"><img src="gfx/emoty/jupi.gif" border="0" height="18" width="25"></a></td>
<td align="center">
<a href="javascript: emot(':papapa:')"><img src="gfx/emoty/papa.gif" border="0" height="16" width="24"></a></td>
<td align="center">
<a href="javascript: emot(':tuptup:')"><img src="gfx/emoty/tuptup.gif" border="0" height="20" width="15"></a></td>
<td align="center">
<a href="javascript: emot(':glaszcze:')"><img src="gfx/emoty/glaszcze.gif" border="0" height="15" width="35"></a></td>
</tr>
<tr>
<td align="center">
<a href="javascript: emot(':-)')"><img src="gfx/emoty/oczko_na.gif" border="0" height="15" width="15"></a></td>
<td align="center">
<a href="javascript: emot(':tancze:')"><img src="gfx/emoty/tancze.gif" border="0" height="29" width="25"></a></td>
<td align="center">
<a href="javascript: emot(':przytul:')"><img src="gfx/emoty/przytul.gif" border="0" height="15" width="36"></a></td>
<td align="center">
<a href="javascript: emot(';P')"><img src="gfx/emoty/jezyk1.gif" border="0" height="15" width="15"></a></td>
</tr>
<tr>
<td align="center">
<a href="javascript: emot(':mruga:')"><img src="gfx/emoty/oczko.gif" border="0" height="15" width="15"></a></td>
<td align="center">
<a href="javascript: emot(':spoko:')"><img src="gfx/emoty/spoko.gif" border="0" height="18" width="25"></a></td>
<td align="center">
<a href="javascript: emot(':*')"><img src="gfx/emoty/cmok.gif" border="0" height="15" width="34"></a></td>
<td align="center">
<a href="javascript: emot(':nenene:')"><img src="gfx/emoty/jezyk2.gif" border="0" height="20" width="15"></a></td>
</tr>
</table>
<p><b>Wył±cz emoty:</b><input type="checkbox" name="emoty" value="1"></p></div>
</td>
</tr>
<tr valign="top">
<td align="right" width="4%"><b>Mail:</b></td>
<td width="27%"><input value="Adres e-mail" onblur="if( this.value == '' ) this.value = 'Adres e-mail';" onfocus="if( this.value == 'Adres e-mail' ) this.value = '';" maxlength="20" name="mail"></td>
</tr>
<tr valign="top">
<td align="right" width="4%"><b>http://</b></td>
<td width="27%"><input value="Twoja strona www" onblur="if( this.value == '' ) this.value = 'Twoja strona www';" onfocus="if( this.value == 'Twoja strona www' ) this.value = '';" maxlength="100" name="www"></td>
</tr>
<tr valign="top">
<td align="right" width="4%"><b>Gg:</b></td>
<td width="27%"><input value="Twój numer gadu-gadu" onblur="if( this.value == '' ) this.value = 'Twój numer gadu-gadu';" onfocus="if( this.value == 'Twój numer gadu-gadu' ) this.value = '';" onkeypress="return onlydec(event,'cos');" maxlength="20" name="kom_gg"></td>
</tr>
<tr valign="top">
<td align="right" width="4%"><b>*Token</b>:</td>
<td width="27%">
<?php echo $img; //wyświetlamy token?></td>
</tr>
<tr valign="top">
<td align="right" width="4%"></td>
<td width="27%"><input value="Powyższy Token" onblur="if( this.value == '' ) this.value = 'Powyższy Token';" onfocus="if( this.value == 'Powyższy Token' ) this.value = '';" onkeypress="return onlydec(event,'cos');" maxlength="20" name="ksiega_token"></td>
</tr>
<tr valign="top">
<td align="right" width="4%"></td>
<td colSpan="2">Wpisałe¶ <b id="ilosc"></b> na 500 możliwych.</td>
</tr>
<tr valign="top">
<td align="right" width="4%"><b>*Tre¶ć:</b></td>
<td colspan="2">
<textarea name="tresc" cols="40" rows="5" value="Treść wpisu" onblur="if( this.value == '' ) this.value = 'Treść Wpisu';" onfocus="if( this.value == 'Treść wpisu' ) this.value = '';" onkeypress="return maxLength2(event,this,'ilosc',500)" onkeyup="maxLength(this,'ilosc',500)" onpropertychange="if(this.all)maxLength(this,'ilosc',500)"></textarea></td>
</tr>
<tr valign="top">
<td align="right" width="4%"></td>
<td colspan="2"><input value="Wpisz" type="submit">
<input value="Wyczy¶ć" type="reset">
<input type="button" onClick="document.location='ksiega.php'" value="Wróć do księgi"> </td>
</tr>
</table>
<p><b>*Pola obowi±zkowe</b></p>
</form>
[/php]

przykład działania: tutaj

Hasło: haslo
Login: login

prosiłbym o zwrócenie uwagi na ustawiania życia sesji bo raz chodzi raz nie...
ODPOWIEDZ