my code stock.com

Snippet options

Download: Download snippet as gaestebuch_beitragphp.php.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

<?php
session_start();
//unbefugte zurück auf die login-seite:
if(!isset($_SESSION['angemeldet']) || $_SESSION['angemeldet'] == false)
  header("Location:login.php");
//echo "angemeldet: {$_SESSION['angemeldet']}<br />";
$error = "";
  if(isset($_POST['benutzer'], $_POST['beitrag']))     {
      $benutzer = trim($_POST['benutzer']);
      $beitrag = trim($_POST['beitrag']);
      //echo "zahl1: $zahl1, zahl2: $zahl2 <br />";
            if(!(empty($benutzer) || empty($beitrag))) //beide felder ausgefüllt ?
      {
    date_default_timezone_set('Europe/Berlin');
    $zeitstempel = date("d.m.Y-H:i:s");
//zeilenumbrüche \n aus dem textfenster in <br /> umwandeln
$beitrag=preg_replace("/(\r\n|\n)/","<br />",$beitrag);
    $adresse = fopen("gaestebuch.txt", "a");
    fwrite($adresse, "$benutzer::$beitrag::$zeitstempel\n");
    fclose($adresse);
    header("Location:gaestebuch.php");
      }
      else
    {
     $error .="Bitte beide Felder ausfüllen.<br />";
    }
          }
?>
<html>
<head>
<title> Gaestebuch </title>
</head>
<body>
<h1>Neuer Beitrag</h1>
  <?php
  if($error != "")
  echo ("<p style=\"color:red\")>$error</p>");
  ?>
<form action="gaestebuch_beitrag.php" method="post">
  Benutzer: <br /><input type="text" size="25%" name="benutzer" /><p />
  Beitrag: <br /><textarea name="beitrag" cols="50" rows="10" /></textarea><br />
  <input type="submit" />
</form>
</body>
</html>

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.