· 6 years ago · Dec 18, 2018, 09:56 AM
1index.php
2
3
4<!DOCTYPE HTML>
5<html lang="pl">
6 <head>
7 <meta charset="utf-8" />
8 <title>PHP Lab05</title>
9 <meta name="description" content="PAI LAB5" />
10 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
11 <link rel="stylesheet" href="style.css" type="text/css" />
12
13 <?php
14 include('config.php');
15 ?>
16 </head>
17 <body>
18 <div id="container">
19 <?php
20 $address = gethostbyname($_SERVER['SERVER_NAME']);
21 $queryIP = "select * from block WHERE address = '".$address."'";
22 $sqlResult = mysql_query($queryIP);
23
24 if (mysql_fetch_row($sqlResult)) {
25 echo "
26 <center>
27 <div style='color:black; padding: 10%;'>
28 <h1>Podany adres (".$address ."), został zablokowany przez administratora strony!</h1>
29 </div>
30 </center>
31 ";
32 }
33 else {
34 ?>
35 <div id="logo">
36
37
38 <div>
39 <h2><i>PAI</i></h2>
40 <h3><i>Lab 5</i></h3>
41 <div><a class="option" href="?index.php">Strona główna</a></div>
42 <div><a class="option" href="?strona=login.php">Administrator</a></div>
43 </div>
44
45 <div style="clear: both;"></div>
46 </div>
47
48 <div id="menu">
49 <ul><b><font color="red">Menu</font></b></br>
50 <?php
51 $allpages = "select * from pages";
52 $result = mysql_query($allpages);
53
54 while ($row = mysql_fetch_row($result)) {
55 echo "
56 <li><i><a href='?strona=".$row[2]."'>".$row[1]."</a></i></li>
57 ";
58 }
59 ?>
60 </ul>
61 </div>
62
63 <div id="content">
64 <?php
65 if (isset($_GET['strona']) && $_GET['strona'] == 'login.php') {
66 echo "
67 <embed src=" . $_GET['strona'] . ">
68 ";
69 }
70 else {
71 if (isset($_GET['strona'])) {
72 echo "
73 <center><embed src=" . $_GET['strona'] . ">
74 ";
75 }
76 else {
77 echo '
78 <h1><i>Witaj na naszej stronie!!!</i></h1>
79 <br>
80 ';
81 }
82 }
83 ?>
84 </div>
85 <div style="clear: both;"></div>
86 <div id="footer">
87 Rafał Warzyński<br />
88 Michał Ślusarczyk<br />
89 Gr. 3ID12B<br />
90 Zespół: 04<br />
91 </div>
92 <?php
93 }
94 ?>
95 </div>
96 </body>
97</html>
98
99
100
101
102
103***********************************************************************************
104admin.php
105
106<!DOCTYPE HTML>
107<html lang="pl">
108 <head>
109 <meta charset="utf-8" />
110 <title>Administrator</title>
111 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
112 <link rel="stylesheet" href="style.css" type="text/css" />
113
114 <?php
115 include('config.php');
116 ?>
117 </head>
118 <body>
119 <div style="color: black;">
120 <?php
121 if (isset($_POST['idremove'])) {
122 $remove = "select * from pages where id = " . $_POST['idremove'];
123 $result = mysql_query($remove);
124 $records = mysql_fetch_row($result);
125
126 if (file_exists($records[2]))
127 unlink($records[2]);
128
129 $removepage =
130 mysql_query("DELETE from `pages` WHERE id=" . $_POST['idremove']);
131
132 if (isset($removepage)) {
133 echo "
134 <center>
135 <h1>Strona została usunięta!</h1>
136 </center>
137 ";
138 }
139 else {
140 echo "
141 <center>
142 <br/>
143 <h1>Błąd usuwania!</h1>
144 <br/>
145 </center>
146 ";
147 echo mysql_errno($conn) . ": " . mysql_error($conn) . "\n";
148 }
149 }
150
151 if (!empty($_POST['pagename'])) {
152 if ($_POST['typ'] == "Z") {
153 $content = $_POST['content'];
154 }
155 else {
156 $fileName = str_replace(" ", "_", $_POST['pagename']) . ".html";
157 $name = "" . $fileName;
158 $fp = fopen($name, "w");
159 fwrite($fp, $_POST['content']);
160 fclose($fp);
161 $content = $name;
162 }
163 $addpage = mysql_query("INSERT INTO `pages`(`address`, `content`) VALUES ( '" . $_POST['pagename'] . "', '".$content."')");
164
165 if (isset($addpage)) {
166 echo "
167 <center>
168 <h1>Strona została dodana do menu.</h1>
169 </center>
170 ";
171 }
172 else {
173 echo "
174 <center>
175 <h1>Błąd!!!</h1>
176 </center>
177 ";
178 echo mysql_errno($conn) . ": " . mysql_error($conn) . "\n";
179 }
180 }
181 ?>
182 <center>
183 <?php echo "<h1>Witaj Szanowny Panie Administratorze ".$userlogin."!</h1>" ?>
184 <h2>Wpisz dane, aby dodać stronę:</h2>
185 <form action='admin.php' method='post'>
186 Podaj nazwÄ™ do menu:
187 <input type=text name=pagename placeholder="nazwa">
188 <br><br>
189 <textarea autofocus cols=100 rows=10 name=content placeholder="domena lub zawartość"></textarea>
190 <br><br>
191 <select name="typ">
192 <option value="W">Wewnętrzna</option>
193 <option value="Z">Zewnętrzna</option>
194 </select>
195 <input type=submit value="DODAJ">
196 <br><br>
197 </form>
198 <form id='deleteForm' action='admin.php' method='POST'>
199 <table>
200 <?php
201 $allpages = "select * from pages";
202 $contentbase = mysql_query($allpages);
203 echo "<h2>Wybierz stronę którą chcesz usunąć:</h2>";
204 while ($row = mysql_fetch_row($contentbase)) {
205 echo "
206
207 <button type='submit' name='idremove' form='deleteForm' value='".$row[0]."'>USUŃ ".$row[1]."
208 </button>
209 ";
210 }
211 mysql_close($conn);
212 header("index.php");
213 ?>
214 </table>
215 </form>
216 <br>
217 <p>
218 <form action='?login.php&opcja=wyloguj' method='post'>
219 <input type='submit' name='wyloguj' value='WYLOGUJ'>
220 </form>
221 </p>
222 <center>
223 </div>
224 </body>
225</html>
226
227
228
229
230**************************************************************************
231login.php
232
233<!DOCTYPE HTML>
234<html lang="pl">
235 <head>
236 <meta charset="utf-8" />
237 <title>Administrator</title>
238 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
239 <link rel="stylesheet" href="style.css" type="text/css" />
240
241 <?php
242 include('config.php');
243 ?>
244 </head>
245 <body>
246 <div style="color: black;">
247 <?php
248 if (isset($_POST['idremove'])) {
249 $remove = "select * from pages where id = " . $_POST['idremove'];
250 $result = mysql_query($remove);
251 $records = mysql_fetch_row($result);
252
253 if (file_exists($records[2]))
254 unlink($records[2]);
255
256 $removepage =
257 mysql_query("DELETE from `pages` WHERE id=" . $_POST['idremove']);
258
259 if (isset($removepage)) {
260 echo "
261 <center>
262 <h1>Strona została usunięta!</h1>
263 </center>
264 ";
265 }
266 else {
267 echo "
268 <center>
269 <br/>
270 <h1>Błąd usuwania!</h1>
271 <br/>
272 </center>
273 ";
274 echo mysql_errno($conn) . ": " . mysql_error($conn) . "\n";
275 }
276 }
277
278 if (!empty($_POST['pagename'])) {
279 if ($_POST['typ'] == "Z") {
280 $content = $_POST['content'];
281 }
282 else {
283 $fileName = str_replace(" ", "_", $_POST['pagename']) . ".html";
284 $name = "" . $fileName;
285 $fp = fopen($name, "w");
286 fwrite($fp, $_POST['content']);
287 fclose($fp);
288 $content = $name;
289 }
290 $addpage = mysql_query("INSERT INTO `pages`(`address`, `content`) VALUES ( '" . $_POST['pagename'] . "', '".$content."')");
291
292 if (isset($addpage)) {
293 echo "
294 <center>
295 <h1>Strona została dodana do menu.</h1>
296 </center>
297 ";
298 }
299 else {
300 echo "
301 <center>
302 <h1>Błąd!!!</h1>
303 </center>
304 ";
305 echo mysql_errno($conn) . ": " . mysql_error($conn) . "\n";
306 }
307 }
308 ?>
309 <center>
310 <?php echo "<h1>Witaj Szanowny Panie Administratorze ".$userlogin."!</h1>" ?>
311 <h2>Wpisz dane, aby dodać stronę:</h2>
312 <form action='admin.php' method='post'>
313 Podaj nazwÄ™ do menu:
314 <input type=text name=pagename placeholder="nazwa">
315 <br><br>
316 <textarea autofocus cols=100 rows=10 name=content placeholder="domena lub zawartość"></textarea>
317 <br><br>
318 <select name="typ">
319 <option value="W">Wewnętrzna</option>
320 <option value="Z">Zewnętrzna</option>
321 </select>
322 <input type=submit value="DODAJ">
323 <br><br>
324 </form>
325 <form id='deleteForm' action='admin.php' method='POST'>
326 <table>
327 <?php
328 $allpages = "select * from pages";
329 $contentbase = mysql_query($allpages);
330 echo "<h2>Wybierz stronę którą chcesz usunąć:</h2>";
331 while ($row = mysql_fetch_row($contentbase)) {
332 echo "
333
334 <button type='submit' name='idremove' form='deleteForm' value='".$row[0]."'>USUŃ ".$row[1]."
335 </button>
336 ";
337 }
338 mysql_close($conn);
339 header("index.php");
340 ?>
341 </table>
342 </form>
343 <br>
344 <p>
345 <form action='?login.php&opcja=wyloguj' method='post'>
346 <input type='submit' name='wyloguj' value='WYLOGUJ'>
347 </form>
348 </p>
349 <center>
350 </div>
351 </body>
352</html>
353
354
355
356******************************************************************************
357konfiguracja bazy danych
358
359<?php
360 $host = 'localhost';
361 $dataBaseLogin = 'root';
362 $dataBasePassword = 'admin';
363 $db = 'labki5';
364
365 $conn = mysql_connect($host, $dataBaseLogin, $dataBasePassword);
366 if (!$conn)
367 die('Error: ' . mysql_error());
368
369 mysql_query('CREATE DATABASE labki5');
370
371
372
373 $db = mysql_select_db($db, $conn);
374 if (!$db)
375 die('Error: ' . mysql_error());
376
377
378
379
380 session_start();
381?>
382
383
384**************************************************************************
385
386
387zad 2 zabezpiecznie :
388
389DROP TABLE IF EXISTS `users`;
390CREATE TABLE IF NOT EXISTS
391`users` (
392 `id` int(10) NOT NULL AUTO_INCREMENT,
393
394`login` varchar(100) NOT NULL,
395
396`password` varchar(100) NOT NULL,
397
398PRIMARY KEY (`id`)
399) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
400
401INSERT INTO
402 `users` (`login`, `password`) VALUES
403 ('admin', '21232f297a57a5a743894a0e4a801fc3'),
404
405
406('Rafal', '21232f297a57a5a743894a0e4a801fc3'),
407 ('Michal', '21232f297a57a5a743894a0e4a801fc3');
408
409
410
411
412DROP TABLE IF EXISTS `block`;
413CREATE TABLE IF NOT EXISTS `block`
414(
415 `id` int(10) NOT NULL AUTO_INCREMENT,
416 `address` varchar(50) NOT NULL,
417 PRIMARY KEY
418
419 (`id`)
420) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
421
422INSERT INTO
423
424 `block` (`address`) VALUES
425 ('192.168.1.12');
426COMMIT;
427
428
429
430
431**********************************************************************
432arkusz styli
433
434* {
435 margin:0;
436 padding:0;
437 position: relative;
438 box-sizing: border-box;
439 font-family: Lucida Console;
440 font-size: 13px;
441}
442
443body {
444 position: absolute;
445 overflow: hidden;
446 background-size: absolute;
447 width: 100%;
448 height: 400%;
449}
450
451#container {
452 width: 90%;
453 margin-left: auto;
454 margin-right: auto;
455}
456
457#logo {
458 background: #FFCCFF;
459 margin-top: 2%;
460 padding: 2%;
461 text-align: center;
462}
463
464.option {
465 float: right;
466 width: 47%;
467 padding: 1%;
468 border: 1px solid #666666;
469 font-size: 25px;
470}
471
472.option:hover {
473 background: #CCFFFF;
474 cursor: pointer;
475 color: white;
476}
477
478#menu {
479 margin-top: 1%;
480 float: left;
481 width: 23%;
482 height: 600px;
483 padding: 2%;
484 text-align: left;
485 background: #CCFFFF;
486 font-size: 25px;
487}
488
489#menu ul li{
490 color: red;
491 padding: 2%;
492 border-top: 2px dashed red;
493 list-style-position: outside;
494}
495
496#content {
497 margin-top: 1%;
498 float: left;
499 width: 74%;
500 height: 600px;
501 padding: 1%;
502 text-align:center;
503 background-image: url('img/bg.jpg');
504}
505
506#footer{
507 top: 350px;
508 padding: 5px;
509 text-align: left;
510 text-transform: uppercase;
511 white-space: pre-wrap;
512}
513
514embed {
515 width: 100%;
516 height: 600px;
517}
518
519
520a:link {
521 color: black;
522 text-decoration: none;
523}
524
525a:visited {
526 color: black;
527 text-decoration: none;
528}
529
530a:hover {
531 color: white;
532 text-decoration: none;
533}
534
535a:active {
536 color: red;
537 text-decoration: none;
538}