4 changed files with 83 additions and 0 deletions
@ -0,0 +1,22 @@ |
|||||
|
<!DOCTYPE html> |
||||
|
<html lang="en"> |
||||
|
<head> |
||||
|
<meta charset="UTF-8"> |
||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||||
|
<title>Document</title> |
||||
|
</head> |
||||
|
<body> |
||||
|
<h1>Formulář</h1> |
||||
|
<h2><a href="/list.php">List</a></h2> |
||||
|
<form action="post.php" method="post"> |
||||
|
<label for="name">Name</label> |
||||
|
<input type="text" id="name" name="name"> |
||||
|
<br> |
||||
|
<label for="msg">Zpráva</label> |
||||
|
<textarea name="msg" id="msg" cols="30" rows="10"></textarea> |
||||
|
<br> |
||||
|
<input type="submit" value="Zapsat"> |
||||
|
</form> |
||||
|
</body> |
||||
|
</html> |
@ -0,0 +1,27 @@ |
|||||
|
<!DOCTYPE html> |
||||
|
<html lang="en"> |
||||
|
<head> |
||||
|
<meta charset="UTF-8"> |
||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||||
|
<title>List</title> |
||||
|
</head> |
||||
|
<body> |
||||
|
<h1>List</h1> |
||||
|
<h2><a href="/">index</a></h2> |
||||
|
<?php |
||||
|
//Kontrola zápisu |
||||
|
if(isset($_GET["m"])){ |
||||
|
echo "<h1>List byl upraven </h1>"; |
||||
|
} |
||||
|
|
||||
|
//načtení souboru pro čtení |
||||
|
$fname = "text.txt"; |
||||
|
$myfile = fopen($fname,"r"); |
||||
|
echo '<div class="blog">'; |
||||
|
echo fread($myfile,filesize($fname)); |
||||
|
echo '</div>'; |
||||
|
fclose($myfile); |
||||
|
?> |
||||
|
</body> |
||||
|
</html> |
@ -0,0 +1,33 @@ |
|||||
|
<?php |
||||
|
// KONTROLA DAT |
||||
|
// $postdata = $_POST; |
||||
|
// echo var_dump($postdata); |
||||
|
|
||||
|
//Načtení dat |
||||
|
$name = $_POST["name"]; |
||||
|
$msg = $_POST["msg"]; |
||||
|
|
||||
|
//nastavení souboru pro zápis |
||||
|
$myfile = fopen("text.txt","a") or die("Nelze otevřít"); |
||||
|
|
||||
|
//formátování zprávy |
||||
|
function validata($data){ |
||||
|
$data = trim($data); |
||||
|
$data = stripslashes($data); |
||||
|
$data = htmlspecialchars($data); |
||||
|
return $data; |
||||
|
} |
||||
|
$name = validata($name); |
||||
|
$msg = validata($msg); // ochrana proti XSS |
||||
|
$msg = str_replace("\n","<br>",$msg); //nahradí zakončení řádku |
||||
|
$fullmsg = "<h3> $name </h3> <p> $msg </p> <hr>"; |
||||
|
|
||||
|
//zapsání do souboru a následné uzavření |
||||
|
fwrite($myfile, $fullmsg); |
||||
|
fclose($myfile); |
||||
|
|
||||
|
//přesměrování na novou stránku |
||||
|
header("Location: /list.php?m=true"); |
||||
|
|
||||
|
// test zápisu |
||||
|
// echo $fullmsg; |
@ -0,0 +1 @@ |
|||||
|
<h3> asd </h3> <p> ddasdasd dqweqwd aysdfasd </p> <hr><h3> asd </h3> <p> asd </p> <hr> |
Loading…
Reference in new issue