siemka dzis wieczorem postanowilem napisac sobie ksiege gosci na klasie nie na funckjach bo mysle ze to prostota i nawet ja laik nie mial bym z tym problemu wiec chcialbyc od was minimalnej pomocy oto skrypty mowie odrazy ze sa dlugie
klasa_ksiegi.php
<?php
class Ksiega {
include('../config.php');
var $zmien;
var $token;
public function Wyswietl_form() {
<head><meta http-equiv="content-type" charset="utf-8" /></head>\n<body>\n<h1>Ksiega gosci</h1>\n<form method="post" />\n<table widht="100%" bgcolor="#4E4E68" border="1" />\n<tr><td>Podaj nick :)<input type="text" name="Nick" /></td></tr>\n<tr><td>Wpisz wiadomosc<input type="text" name="message" /></td></tr>\n<tr><td width="80"><img src="token.php"></td><td><input type="text" name="token" /></td></tr>\n<tr><td align="right"><INPUT TYPE=image VALUE=submit src="buttons.php"/></td></tr>\n");
}
public function bbcode() {
$this->zmien = preg_replace("#(.*?)#si", "<A HREF='2' TARGET='top'>3</A>", $this->zmien); $this->zmien = str_replace(":D","<img src='obrazki/biggrin.gif' />", $this->zmien); $this->zmien = str_replace(":)","<img src='obrazki/smile.gif' />", $this->zmien); $this->zmien = str_replace(":(","<img src='obrazki/confused.gif' />", $this->zmien); $this->zmien = str_replace(";p","<img src='obrazki/tongue.gif' />", $this->zmien); $this->zmien = str_replace(":]","<img src='obrazki/cool.gif' />", $this->zmien); $this->zmien = str_replace("[:","<img src='obrazki/bigrazz.gif' />", $this->zmien); $this->zmien = str_replace("()","<img src='obrazki/wink.gif' />", $this->zmien); $this->zmien = preg_replace("#(.*?)#si", "<i>1</i>" $this->zmien); $this->zmien = preg_replace("#(.*?)#si", "<b>1</b>" $this->zmien); $this->zmien = preg_replace("#[ins](.*?)[/ins]#si", "<ins>1</ins>", $this->zmien); $this->zmien = preg_replace("#[small](.*?)[/small]#si", "<small>1</small>", $this->zmien); $this->zmien = preg_replace("#[big](.*?)[/big]#si", "<big>1</big>", $this->zmien); return $this->zmien;
}
public function Sesja_tokena() {
$this->token = $_SESSION['randtoken'];
}
public function Generuj_token() {
$generuj_liczby = rand(1
, 1000
); $this->token = substr(md5($generuj_liczby)0
, 6
); $_SESSION['randtoken'] = $this->token;
}
public function Zwroc_token() {
return $this->token;
}
public function Resetuj() {
$_SESSION['randtoken'] = "";
$this->token = "";
}
public function Zrob_obrazek_tokena() {
header("Content-type: image/png"); $image = @imagecreate(100,20);
if($image) {
$background = imagecolorallocate($image, 0,0,0);
$text = imagecolorallocate($image, 255,255,235);
imagestring($image, 4, 25,5, $this->token, $text);
header("Content-type: image/png"); imagepng($image);
imagedestroy($image);
}
}
$this->data = date('j/n/Y H:i:s;'); }
public function Dodaj_wpis() {
$this->ip = $_SERVER['REMOTE_ADRESS'];
if($token->Zwroc_token() == $_POST['token'] && !empty($this->nick) && !empty($this->message)) {
$db = mysql_connect($this->pasy['host'], $this->pasy['login'], $this->pasy['haslo']);
$db->select_db($this->pasy['baza']);
echo('Polaczenie z baza niemozliwe prosze sprobowac pozniej');
return;
}
$this->zapytanie = sprintf('insert into ksiega(nick,message,data,ip) values('%s
', '%s
','$this->data', '$this->ip')');
$db->query($zapytanie) or
die('Polaczenie nie mozliwe prosze sprobowac pozniej');
if($this->zapytanie) {
echo('<Br><center><h2>Dziekuje za wpis<Br></h2></center>'); else {
echo('Prosze wypelnic wszystkie pola'); }
else {
echo('Podaj wlasciy token');
$token->Resetuj();
}
}
}
}
public function Pokaz_ksiege() {
$db = mysql_connect($this->pasy['host'], $this->pasy['login'], $this->pasy['haslo']);
$db->select_db($this->['baza']);
echo('Polaczenie z baza niemozliwe prosze sprobowac pozniej');
return;
}
$this->zapytanie('select nick,message,data from ksiega order by data desc')
$wynik = $db->query($zapytanie);
while($tab = $wynik->fetch_assoc()) {
echo('<tr><td>"Dodal: ".'$this->tab['nick'].'</td></tr> <tr><td>'.$this->tab['message'].'</td></tr>\n</table>\n</form>\n</body>\n</html>\n');
?>
to index.php
<?php
include('klasa_ksiegi.php');
$token = new Ksiega;
$token->Generuj_token();
$ksiega_gosci = new Ksiega;
$ksiega_gosci->Wyswietl_form();
$ksiega_gosci->Dodaj_wpis();
$ksiega_gosci->Pokaz_ksiege();
?>
token.php
<?php
include('klasa_ksiegi.php');
$token = new Ksiega;
$token->Sesja_tokena();
$token->Zrob_obrazek_tokena();
?>
i buttons.php
<?php
header("Content-type: image/png"); $image = @ImageCreate(60,25);
$tlo = imagecolorallocate($image, 0,0,0);
$kolor_tekst = imagecolorallocate($image, 5,255,47);
$text = imagestring($image, 3,8,5, 'wyslij', $kolor_tekst);
header("Content-type: image/png"); imagepng($image);
imagedestroy($image);
?>
Watpie zeby komus sie chcialo czytac caly kod ale przynajmniej zeby zobaczyl na klase bo cos chyba zle zrobilem albo czegos nie zrozumialem
Ten post edytował marcio 5.10.2007, 23:27:56