Advertisement
Guest User

Untitled

a guest
Dec 9th, 2018
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.20 KB | None | 0 0
  1. //zad3
  2. <h2>JEŚLI CHCESZ DODAĆ KOLEJNY WPIS <br>
  3. <a href="zad3_dodaj.php"> naciśnij tutaj </a>
  4. </h2>
  5.  
  6. <?php
  7. echo '<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >';
  8. if ($_SERVER['REQUEST_METHOD'] == "POST") {
  9. $napis = $_POST['name']." | ".$_POST['email']." | ".$_POST['desc']."\n";
  10. $file = fopen("DANE.TXT", "a");
  11. fputs($file, $napis);
  12. fclose($file);
  13. echo " <TABLE border='10' bgcolor=yellow width=400 frame=border>
  14. <tr>
  15. <th> NAZWISKO I IMIE </th>
  16. <th> ADRES POCZTOWY </th>
  17. <th> OPIS </th>
  18. </tr>";
  19. $file = fopen("DANE.TXT", "r");
  20. $plik = file("DANE.TXT");
  21. for($x = 0; $x < count($plik); $x++) {
  22. $t1 = explode("|", $plik[$x]);
  23. echo "<tr>";
  24. for($y = 0; $y < count($t1); $y++) {
  25. echo "<th>".$t1[$y]."</th>";
  26. }
  27. echo "</tr>";
  28. }
  29. echo "</TABLE>";
  30. }
  31. ?>
  32.  
  33. //zad3_dodaj
  34. <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
  35. <form action="zad3.php" method="POST">
  36. <table>
  37. <tr>
  38. <td>imie i nazwisko:</td>
  39. <td><input type="text" name="name"></td>
  40. </tr>
  41. <tr>
  42. <td>twój adres e-mail:</td>
  43. <td><input type="mail" name="email"></td>
  44. </tr>
  45. <tr>
  46. <td>treść listu:</td>
  47. <td><textarea name="desc"></textarea></td>
  48. </tr>
  49. </table>
  50. <input type="submit" value="wyślij dane">
  51. <input type="reset" value="wyczyść dane">
  52. </form>
  53. //zad3_login
  54. <?php
  55. session_start();
  56. if (isset($_SESSION['login']) && isset($_SESSION['password'])) {
  57. $username = $_SESSION['login'];
  58. $password = $_SESSION['password'];
  59. }
  60. else {
  61. $username = NULL;
  62. $password = NULL;
  63. }
  64. if(empty($username) || empty($password)) {
  65. ?>
  66. <form action="?case=register" method="post">
  67. <table>
  68. <tr>
  69. <td><b>Rejestracja:</b></td>
  70. <tr>
  71. <td>Login:</td>
  72. <td><input type="text" name="username"></td>
  73. </tr>
  74. <tr>
  75. <td>Password:</td>
  76. <td><input type="password" name="password"></td>
  77. </tr>
  78. <tr>
  79. <td><input type="submit" value="Register"></td>
  80. </tr>
  81. </table>
  82. </form>
  83. <form action="?case=login" method="post">
  84. <table>
  85. <tr>
  86. <td><b>Logowanie:</b></td>
  87. <tr>
  88. <td>Login:</td>
  89. <td><input type="text" name="username"></td>
  90. </tr>
  91. <tr>
  92. <td>Password:</td>
  93. <td><input type="password" name="password"></td>
  94. </tr>
  95. <tr>
  96. <td><input type="submit" value="Login"></td>
  97. </tr>
  98. </table>
  99. </form>
  100.  
  101.  
  102. <?php
  103. }
  104. else {
  105. echo "Zalogowano jako: <br>".$username;
  106. echo "<br><a href=?case=logout>Wyloguj</a>";
  107. }
  108. if (isset($_GET['case'])) {
  109. $case = $_GET['case'];
  110. switch($case) {
  111. case 'register':
  112. if(isset($_POST['username'], $_POST['password']) && !empty($_POST['username']) && !empty($_POST['password'])) {
  113. $login1 = htmlspecialchars(trim($_POST['username']));
  114. $password1 = htmlspecialchars(trim(md5($_POST['password'])));
  115. $user = fopen("uzytkownicy.txt", "a+");
  116. while($line = fgets($user)) {
  117. $user1 = explode("|", $line);
  118. if(trim($user1[0]) == $login1) {
  119. $exists = true;
  120. break;
  121. }
  122. $exists = false;
  123. }
  124. if($exists) {
  125. echo "<span style='color:red;'>Uzytkownik o podanej nazwie juz istnieje</span>";
  126. }
  127. else {
  128. fputs($user, $login1."|".$password1."\n");
  129. }
  130. fclose($user);
  131. break;
  132. }
  133. else {
  134. echo "<span style='color:blue;'>Wypelnij wszystkie pola!</span>";
  135. }
  136. header('Location zad1.php');
  137. break;
  138.  
  139. case 'login':
  140. if(isset($_POST['username'], $_POST['password']) && !empty($_POST['username']) && !empty($_POST['password'])) {
  141. $login2 = htmlspecialchars(trim($_POST['username']));
  142. $password2 = htmlspecialchars(trim(md5($_POST['password'])));
  143. $user2 = fopen("uzytkownicy.txt", "a+");
  144. while($line1 = fgets($user2)) {
  145. $user3 = explode("|", $line1);
  146. if(trim($user3[0]) == $login2 && trim($user3[1]) == $password2) {
  147. $exists = true;
  148. break;
  149. }
  150. $exists = false;
  151. }
  152. if(!$exists) {
  153. echo "<span style='color:red;'>Podana nazwa uzytkownika lub haslo sa niepoprawne</span>";
  154. break;
  155. }
  156. else {
  157. $_SESSION['login'] = $login2;
  158. $_SESSION['password'] = $password2;
  159. header("Location: zad3_login.php");
  160. break;
  161. }
  162. fclose($user2);
  163. }
  164. else {
  165. echo "<span style='color:blue;'>Wypelnij wszystkie pola!</span>";
  166. break;
  167. }
  168. case 'logout':
  169. session_unset();
  170. session_destroy();
  171. header('Location: zad3_login.php');
  172. break;
  173. }
  174. }
  175. ?>
  176. //zad3_upload
  177. <form action="zad3_upload.php" method="post" enctype="multipart/form-data">
  178. Wybierz plik: <input type="file" name="file"><br>
  179. <input type="submit" value="Wgraj">
  180. </form>
  181.  
  182. <?php
  183. function pre_r($array){
  184. echo '<pre>';
  185. print_r($array);
  186. echo '</pre>';
  187. }
  188.  
  189. if(isset($_FILES['file'])) {
  190. pre_r($_FILES);
  191. $ext_error = false;
  192. $extensions = array('zip', 'rar');
  193. $file_ext = explode('.', $_FILES['file']['name']);
  194. $file_ext = end($file_ext);
  195. if(!in_array($file_ext, $extensions)) {
  196. $ext_error = true;
  197. }
  198.  
  199. if($_FILES['file']['error']) {
  200. switch($_FILES['file']['error']) {
  201. case 1:
  202. echo '<p> The file is bigger than this PHP installation allows</p>';
  203. break;
  204. case 2:
  205. echo '<p> The file is bigger than this form allows</p>';
  206. break;
  207. case 3:
  208. echo '<p> Only part of the file was uploaded</p>';
  209. break;
  210. case 4:
  211. echo '<p> No file was uploaded</p>';
  212. break;
  213. }
  214. }
  215. elseif($ext_error) {
  216. echo "Invalid file extension!";
  217. }
  218. else {
  219. echo "Success! Image has been uploaded!";
  220. move_uploaded_file($_FILES['file']['tmp_name'], 'files/'.$_FILES['file']['name']);
  221. }
  222. }
  223. ?>
  224. //zad4_lastseen
  225. <?php
  226. if(isset($_COOKIE['test'])) {
  227. echo "Ostatni raz byles na tej stronie ".date('d.m.Y H:i:s', $_COOKIE['test']);
  228. setcookie('test', time());
  229. }
  230. else
  231. {
  232. setcookie('test', time(), time() + (60 * 60 * 24 * 365 * 5));
  233. header('Location: zad4_lastseen.php');
  234. }
  235. ?>
  236. //zad4_lifetime
  237. <?php
  238. if(isset($_COOKIE['test'])){
  239. echo "To ciasteczko zniknie o godzinie: ".date("H:i:s", $_COOKIE['test'])."<br>";
  240. } else {
  241. setcookie('test', time()+(60), time()+(60));
  242. echo "Stworzono nowe ciasteczko<br>";
  243. }
  244. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement