Autor Zpráva
Clogg
Profil
Zdravím. Mám knihu hostů:
--formulář pro vkládání příspěvků:
<form method="post" action="gb-exec.php" style=" background-image:url(../images/chat_form.png); background-repeat:no-repeat;position:relative; padding-left:13px; padding-right:">
    <fieldset>
        <label for="name" >JMÉNO:</label>
        <label for="message">Zpráva:</label>
        <input type="text" class="textfield" name="name" id="name" size="27" />
        <textarea name="message" id="message" rows="6" cols="32"></textarea>
        <label for="email">Váš email (nezobrazí se):</label>
        <input type="text" class="textfield" name="email" id="email" size="27" />
        <label for="spam">Napište '<b><?php echo $antispam_word; ?></b>':</label>
        <input type="text" name="spam" id="spam" size="5" value="" />
        <input type="submit" name="submit" value="odeslat" />
        <input type="hidden" name="i" value="<?php echo (int)$_GET['i']; ?>" />
    </fieldset>
</form>

--A část, která načítá obsah souboru, kde se ukládaj zprávy:
<?php 
$gbfile = 'gbcontentfile.php';
$fh = @fopen($gbfile, "r");
$fcontent = @fread($fh, filesize($gbfile));
if($fcontent){
    $cnt = substr_count($fcontent,'<?php /* ');
    $cnt = $cnt/2;
    $maxp = 0;
    if($cnt>$page_comments)$maxp = (int)($cnt/$page_comments);
    preg_match_all("/\<\?php .*? \?\>(.*?)\<\?php .*? \?\>/is", $fcontent, $entries);
    $ini = $page*$page_comments;
    $end = ($page+1)*$page_comments;
$ovo = array('<1>','<2>','<3>','<4>');
$sovim = array(
"<div class=\"gbsign\">
    <p><span class=\"gbname\">",
"</span> <span class=\"gbdate\">",
"</span>
    </p>
    <p class=\"gbmessage\">",
"
    </p>
</div>
"
);
    for($j=$ini;$j<$end;$j++)echo str_replace($ovo,$sovim,$entries[1][$j]);
    if($maxp>-1){
        echo '<p>'.strstr($fcontent,'<!--').' Page '; $gap = "";
        for($j=0;$j<$maxp+1;$j++){
            if($j==0||$j==$maxp||($j-$page)*($j-$page)<26){
                echo $gap; $gap = "";
                if($j!=$page)echo "- <a href=\"guestbook.php?p=".$j.$si."\">".($j+1)."</a> " ;
                else echo "- <b>".($j+1)."</b> " ;
            }
            else $gap = "<b>.....</b>"; 
        }
        echo '</p>';
    }
}
?>
Zápis do databáze probíhá prostřednictvím tohoto:
<?php
if($_SERVER['REQUEST_METHOD'] != "POST")exit;
$cururl = str_replace('gb-exec.php','guestbook.php','.$_SERVER["REQUEST_URI].$_SERVER["REQUEST_URI].$_SERVER["REQUEST_URI]http://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);
//if($cururl != $_SERVER['HTTP_REFERER'])exit;
require_once('mygb.php');
if($e_mail==''||$e_mail=='you@email.com'){
    echo 'to use the guestbook, please edit "mygb.php" file and change there email address and other parameters. thank you. lazar';
    exit;
}
$ip = $_SERVER['REMOTE_ADDR'];
$hash_ip = md5($mysecretword.$ip);
$time = time() + $time_zone*60*60;
$hash_time = md5($mysecretword.$time);

if (!file_exists('bips.php'));
else {
    $fcontent = @file_get_contents('bips.php');
    $ipstr = "<?php /* ".$ip." */ ?>";
    if(strpos($fcontent, $ipstr)>0)exit;
}

function nlp2nl($str) {
    return preg_replace("/(\r\n|\n|\r)+/", "\n", $str);
}
function st2s($str) {
    return preg_replace('/\s\s+/', ' ', preg_replace("/\t+/", " ", $str));
}

$name = stripslashes(strip_tags($_POST['name']));
$email = stripslashes(strip_tags($_POST['email']));
$message = stripslashes(strip_tags($_POST['message']));
$messageF = preg_replace("/(\r\n|\n|\r)/", "<br />", $message);
$spam = strip_tags(str_replace("'",'',$_POST['spam']));

if($enable_guest_images&&$default_guest_image){
    if($email)$grav_url = "http://www.gravatar.com/avatar.php?gravatar_id=".md5(strtolower($email))."&default=".urlencode($default_guest_image)."&size=".$guest_image_size; //"http://www.somewhere.com/guest.jpg" is default
    else $grav_url = $default_guest_image;
    if($grav_url)$gravatar = "<img src=\"$grav_url\" />";
    else $gravatar = "";
}
else $gravatar = "";

if($_POST['i']!=0){$i = (int)$_POST['i'];$si = '?i='.$i;}
else $si = '';

if(strtolower($spam)==$antispam_word&&strlen(trim($message))>2){
    $file = "gbcontentfile.php";
    if (!file_exists($file)) {
        touch($file);
        $fc = fopen($file, 'w');
        $copyrightlink = "
        <!-- COPYRIGHT -->
        <!-- Contact author thru the website below if you wish to remove this copyright link. -->
        <a href=\"http://www.inverudio.com/guestbook/\"><img style=\"border:0px;\" src=\"book.png\" alt=\"guestbook\"/></a>
        <!-- END OF COPYRIGHT -->
        ";
        fwrite($fc, $copyrightlink);
        fclose($fc);
    }
    $fh = @fopen($file, "r");
    $fcontent = @fread($fh, filesize($file));
    $tzs = '+';if($time_zone < 0)$tzs = '';
    $timestr = gmdate("j. n. Y  G:i",$time)." GTM"." $tzs$time_zone";
    $newcontent = "
<?php /* IP".$hash_ip." f".$hash_time." */ ?><1>".$gravatar." ".$name."<2>".$timestr."<3>".$messageF."<4><?php /* t".$hash_time." IP".$hash_ip." */ ?>
";
    $newcontent = st2s($newcontent);
    $towrite = nlp2nl("$newcontent $fcontent");
    fclose($fh);
    $fh2 = fopen($file, 'w+');
    fwrite($fh2, $towrite);
    fclose($fh2);
    $mailmessage = "
".$gravatar." ".$name." napsal: 

".$message.


Obsah toho skladovacího souboru s jednou zprávou vypadá takhle:
          <?php /* IPb21842736d04344dd4912760fb78ce78 fa56697f46a800d0611456102cc8a93e9 */ ?><1> Lukáš Kadeřábek<2>24. 2. 2012 GTM +1<3>Těším se na mládežnický english camp. S pozdravem  Lukáš K. < <4><?php /* ta56697f46a800d0611456102cc8a93e9 IPb21842736d04344dd4912760fb78ce78 */ ?>                                    
A já bych chtěl, aby se má index stránka vždy podívala, co je v té knize (gbcontentfile.php) přidáno naposled a zobrazila to..
PHP téměř vůbec nerozumím, proto, jestli někdo víte, jak na to, vysvětlete mi to radši polopatičtěji. Moc děkuji.
Toto téma je uzamčeno. Odpověď nelze zaslat.

0