Mam navstevnu knihu
http://jan.fecik.sk/kniha-navstev.html a chcem tam pridat overovaci kod, stranka je robena nasledovne
kniha-navstev.html je len rewrite suboru kniha-navstev.php a ten obsahuje:
Kód:
<?php
session_start();
if (!isset($_GET['code'])) {
for ($i=0;$i<5;$i++)
{
while(strlen($str[$i])!=1){
$random=rand(48,123);
if( ($random>47 && $random<58) || ($random>96 && $random<123) ||
($random>64 && $random<91) ){
$str[$i] = chr($random);
}
}
$text .= $str[$i];
}
$_SESSION['string']= $text;
$GLOBALS['text'] = $text;
}
elseif (isset($_GET['code'])){
$GLOBALS['text'] = $_SESSION['string'];
$obrazek = imagecreatefrompng("images/pozadie.png");
for ($i=0; $i<5; $i++){
$textcolor = imagecolorallocate($obrazek,rand(0,130),rand(0,130),rand(0,130));
$pismenko = substr($GLOBALS['text'],0+$i,1);
imagettftext ($obrazek,rand(15,25),rand(-45,45),15+($i*38),35, $textcolor,"images/font.ttf",$pismenko) ;
}
header("Content-type: image/png");
imagepng($obrazek);
imagedestroy ($obrazek);
exit();
};
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Kniha návštev</title>
<?php
@include ('includes/meta.inc');
@include ('includes/header.inc');
@include ('includes/menu.inc');
@include ('includes/kniha-navstev.inc');
@include ('includes/footer.inc');
?>
</html>
Ako je vidiet tak je tam na zaciaktu php script ktory pomocou session generuje obrazok s nahodnym textom, link na obrazok je
http://jan.fecik.sk/kniha-navstev.html?codeDalej subor obsahuje 5x include pricom meta.inc, header.inc, menu.inc a footer.inc je na kazdej stranke rovnaky a pre tento problem je aj nepodstatne uvadzat kod, ani jeden znich nejaky php script neobsahuje. Dolezity je kniha-navstev.inc, ten vyzera nasledovne:
Kód:
<?php
$gbfile = "includes/kniha-navstev.dat";
$thisfile = "kniha-navstev.html";
$dateshow = "Y-m-d - H:i:s";
$date = date("$dateshow");
$thankstxt = "<meta http-equiv='refresh' content='1;URL=$thisfile'><p>Thank you for writing in my guestbook!<br>You will be sent back in 3 seconds. If not click <a href='$thisfile'>here</a></p>";
$errornoname = "<meta http-equiv='refresh' content='1;URL=$thisfile'><p>You have to enter a name!<br>You will be sent back in 3 seconds. If not click <a href='$thisfile'>here</a></p>";
$errornomsg = "<meta http-equiv='refresh' content='1;URL=$thisfile'><p>You have to enter a message!<br>You will be sent back in 3 seconds. If not click <a href='$thisfile'>here</a></p>";
$name = htmlentities(strip_tags($_POST['name']));
$message = nl2br(htmlentities(strip_tags($_POST['message'])));
$message = str_replace(array("\r", "\n"), '', $message);
$message = wordwrap($message, 75, "<br />", true);
$printpage = "<table width=\"400\" border=\"0\" align=\"center\" bordercolor=\"#CCCCCC\"><tr><td width=\"80\"><strong>Dátum:</strong></td><td width=\"320\">$date</td></tr><tr><td><strong>Meno:</strong></td><td>$name</td></tr><tr><td><strong>Správa:</strong></td><td>$message</td></tr></table><br> \n";
switch($_GET['id'])
{
default:
?>
<table align="center"><form action="kniha-navstev.html?id=submit" method="post" name="submitform">
<tr><td><strong>Meno:</strong></td><td><input type="text" name="name" size="30" maxlength="50"></td></tr>
<tr><td valign="top"><strong>Správa:</strong></td><td><textarea name="message" cols="30" rows="7"></textarea></td></tr>
<tr><td valign="top"><strong>Kód:</strong></td><td><img src = "kniha-navstev.html?code" alt="Overovací kód"></td></tr>
<tr><td><strong>Opísať:</strong></td><td><input type="text" name="kod" size="15"></td></tr>
<tr><td></td><td><input type="submit" name="submit" value="Poslať"></td></tr>
</form></table><br>
<?php
$gb = file($gbfile);
$gb = array_reverse($gb);
foreach ($gb as $guestbook) { echo stripslashes($guestbook); }
break;
case submit:
if($name == "")
{
echo $errornoname;
}
elseif($message == "")
{
echo $errornomsg;
}
elseif($done == "")
{
$writeinfo = $printpage;
$printer = fopen($gbfile,"a");
fwrite($printer,$writeinfo);
fclose($printer);
echo $thankstxt;
}
break;
}
?>
Vedel by mi niekto pomoct s integraciou toho overovania do tejto navstevnej knihy?
Overovat sa to da pomocou tohoto scriptu:
Kód:
<?php
session_start();
if (isset($_SESSION['string']))
{
if( $_SESSION['string'] == $_POST['kod'] )
{
echo 'Ano kód jsi opsal správně. Gratuluji';
}
else
{
echo 'Spamery nemám rád.... Zadal jsi špatný kód';
}
}
else
{
echo 'Podvod!!!!!!! Pokusil jsi se sem dostat bez opsání kódu.<br/>';
echo 'IP: ' . $_SERVER['REMOTE_ADDR'] . ' Byla zaznamenána.';
}
?>