askIT

  • main_navigation_menu_icon.png
  • ic_more_vert.png

PHP - Filer - Enkel gjestebok

<?php
$entriesDir 
"entries";

/*- Finnes mappen entries? ----------------------------------------- */
if(!(is_dir("$entriesDir/"))){
    
mkdir("$entriesDir/"0777);
}

/*- Hent GET-variabler --------------------------------------------- */
if(isset($_GET['action'])) {
    
$action $_GET['action'];
    
$action strip_tags(stripslashes($action));
}
// Vi bruker $action for å se hva brukeren ønsker å gjøre

if($action == ""){
    
/*- Vi viser skjemaet og innleggene ------------------------ */
    
echo"
    <h3>Gjestebok</h3>

    <p><a href=\"php_filer_enkel_gjestebok.php?action=sign\">Signer gjesteboken</a></p>

        

    <!-- Innlegg -->
        <p></p>
        "
;
        
$filenames "";
        
$dir "$entriesDir/";
        
$dirLen strlen($dir);
        
$dp = @opendir($dir);

        while(
$file = @readdir($dp)) $filenames [] = $file;
        for (
$i 0$i count($filenames); $i++){
            @
rsort($filenames);
            
$content $filenames[$i];
            
$file_path "$dir$content";
            
            if(
$file_path != "$entriesDir/.." && $file_path != "$entriesDir/."){
                include(
"$file_path");
                echo
"
                <table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">
                 <tr>
                  <td class=\"outline\">
                    <table width=\"100%\" cellspacing=\"1\" cellpadding=\"0\">
                     <tr>
                      <td class=\"headcell\">
                        <span><b>
$nameSav</b></span>
                      </td>
                     </tr>
                     <tr>
                      <td class=\"bodycell\">
                        <span>
$messageSav</span>
                      </td>
                     </tr>
                    </table>
                  </td>
                 </tr>
                </table>
                <p>&nbsp;</p>
                "
;
            }
        }
        echo
"
    <!-- //Innlegg -->
    "
;

}
elseif(
$action == "sign"){
    echo
"

    <!-- Skjema for nye innlegg -->
        <h3>Signer gjesteboken</h3>
        <form method=\"POST\" action=\"php_filer_enkel_gjestebok.php?action=do_sign\" enctype=\"multipart/form-data\">
    
        <p>
        <b>Navn:</b><br />
        <input type=\"text\" name=\"inp_name\" size=\"48\" /><br />
        </p>

        <p>
        Hilsen:</b><br />
        <textarea name=\"inp_message\" rows=\"5\" cols=\"40\"></textarea>
        </p>
        
        <p>
        <input type=\"submit\" value=\"Send hisen\" />
        </p>
        
        </form> 
    <!-- //Skjema for nye innlegg -->
    "
;
}
elseif(
$action == "do_sign"){
    
/*- Vi henter data fra hilsen ----------------------------- */
    
    
$inp_name $_POST['inp_name'];
    
$inp_name htmlspecialchars($inp_name);
    
$inp_name trim($inp_name);

    
    
$inp_message $_POST['inp_message'];
    
$inp_message htmlspecialchars($inp_message);
    
$inp_message trim($inp_message);
    
$inp_message str_replace("\n","<br />","$inp_message");
    
$inp_message str_replace("'","&#39;","$inp_message");

    if(empty(
$inp_name) OR empty($inp_message)){
        echo
"<p>Du må fylle ut alle feltene for å signere gjesteboken!</p>";
    }
    else{
        
// Begge feltene er signert, vi kan lagre hilsen

        
$input="<?php
        \$nameSav    = \"
$inp_name\";
        \$messageSav = '
$inp_message';
        ?>"
;

        
$id date("ymdhis");

        
$fh fopen("$entriesDir/$id.php""w") or die("can not open file");
        
fwrite($fh$input);
        
fclose($fh);

        echo
"
        <h3>Takk for ditt innlegg</h3>

        <p>Du blir nå overført tilbake</p>

        <meta http-equiv=\"refresh\" content=\"1;url=php_filer_enkel_gjestebok.php\">
        "
;
    }

}
?>

mark_down.png Annonse

Akuratt nå: Ask IT bruker og anbefaler one.com for domener, e-post og webhotell!
hva-er-ditt-nye-domene.com
Besøk oss på one.com