Recent Changes - Search:

Hauptmenue (edit)

Php /

DoppelPostVerhindern

<< BaseConvert | PhpSchnipsel | ErrorReporting >>

<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors', TRUE); // evtl. hilfreich
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Doppelposts verhindern</title>
</head>
<body>
<a href="<?=$_SERVER['PHP_SELF']?>">Self</a> <br />
<?php
if (isset($_POST['submit']))
{
  if (isset($_SESSION['waechter']) && ($_POST['waechter'] == $_SESSION['waechter']))
  {
    $_SESSION['waechter'] = md5(rand()); // wieder unverfänglich machen
    auswertung();
  } else
  {
    ungueltig();
  } 
}else
{
  $_SESSION['waechter'] = md5(rand());
  formular();
}

function formular()
{ ?>
<form name="form1"  method="post" action="<?=$_SERVER['PHP_SELF']?>">
  <input type="hidden" name="waechter" value="<?=$_SESSION['waechter']?>">
  <input type="text" name="text" >
  <br />
  <input type="submit" name="submit" value="Senden" >
</form>
<?php }

function auswertung()
{
  echo 'Es wurde: '.$_POST['text'].' eingegeben!';
}

function ungueltig()
{
  echo "Fehler: <br />";
  if (isset($_COOKIE[session_name()]))
  {
    echo "ANGRIFF oder DOPPELPOST";
  } else
  {
    echo "Cookies sind leider abgeschaltet";
  } 
}

?>
</body>
</html>

<< BaseConvert | PhpSchnipsel | ErrorReporting >>

Edit - History - Print - Recent Changes - Search
Page last modified on September 19, 2006, at 11:38 AM