verbetering website beveiliging enz..
Ik ben bezig met m'n eerste website in php. Nu is hij bijna af, maar ik denk dat er heel wat dingen beter kunnen, zoals beveiliging, efficiëntie enz. Hieronder is de code. Zouden jullie willen kijken naar dingen die beter kunnen?
alvast bedankt!
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
session_start();
include ("include/db_conn.php");
$pag = mysql_real_escape_string($_GET["pag"]);
$art = mysql_real_escape_string($_GET["art"]);
$aud = mysql_real_escape_string($_GET['aud']);
$pid = $pag ? $pag : home;
$sql = "SELECT * FROM menu WHERE pagina = '" .$pid. "'";
$res = mysql_query($sql) or trigger_error(mysql_error());
$row = mysql_fetch_assoc($res);
$pid_page1s = $art ? $art : "";
$sql_page1s = "SELECT titel, tekst FROM page1s WHERE titel = '" .$pid_page1s. "'";
$res_page1s = mysql_query($sql_page1s) or trigger_error(mysql_error());
$row_page1s = mysql_fetch_assoc($res_page1s);
$sql_page1s_counter = "UPDATE page1s SET counter = (counter + 1) WHERE titel = '" .$pid_page1s. "'";
$res_page1s_counter = mysql_query($sql_page1s_counter) or trigger_error(mysql_error());
$pid_audio = $aud ? $aud : "";
$sql_audio = "SELECT titel, locatie FROM audio WHERE titel = '" .$pid_audio. "'";
$res_audio = mysql_query($sql_audio) or trigger_error(mysql_error());
$row_audio = mysql_fetch_assoc($res_audio);
$sql_audio_counter = "UPDATE audio SET counter = (counter + 1) WHERE titel = '" .$pid_audio. "'";
$res_audio_counter = mysql_query($sql_audio_counter) or trigger_error(mysql_error());
if (isset($aud)){
header("location: /".$row_audio["locatie"]."");
exit();
}
include ("include/stats.php");
?>
session_start();
include ("include/db_conn.php");
$pag = mysql_real_escape_string($_GET["pag"]);
$art = mysql_real_escape_string($_GET["art"]);
$aud = mysql_real_escape_string($_GET['aud']);
$pid = $pag ? $pag : home;
$sql = "SELECT * FROM menu WHERE pagina = '" .$pid. "'";
$res = mysql_query($sql) or trigger_error(mysql_error());
$row = mysql_fetch_assoc($res);
$pid_page1s = $art ? $art : "";
$sql_page1s = "SELECT titel, tekst FROM page1s WHERE titel = '" .$pid_page1s. "'";
$res_page1s = mysql_query($sql_page1s) or trigger_error(mysql_error());
$row_page1s = mysql_fetch_assoc($res_page1s);
$sql_page1s_counter = "UPDATE page1s SET counter = (counter + 1) WHERE titel = '" .$pid_page1s. "'";
$res_page1s_counter = mysql_query($sql_page1s_counter) or trigger_error(mysql_error());
$pid_audio = $aud ? $aud : "";
$sql_audio = "SELECT titel, locatie FROM audio WHERE titel = '" .$pid_audio. "'";
$res_audio = mysql_query($sql_audio) or trigger_error(mysql_error());
$row_audio = mysql_fetch_assoc($res_audio);
$sql_audio_counter = "UPDATE audio SET counter = (counter + 1) WHERE titel = '" .$pid_audio. "'";
$res_audio_counter = mysql_query($sql_audio_counter) or trigger_error(mysql_error());
if (isset($aud)){
header("location: /".$row_audio["locatie"]."");
exit();
}
include ("include/stats.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>
Code (php)
1
<?php echo "Page - ".$row["titel_header"]." | ". str_replace("_", " ", $row_page1s["titel"]); ?>
<link href="css.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
<div id="header">
<ul id="nav">
<li><a href="index.php">startpagina</a></li>
<li><a href="?pag=page1s">page1s</a></li>
<li><a href="?pag=audio">audio</a></li>
<li><a href="?pag=biografie">biografie</a></li>
<li><a href="?pag=links">links</a></li>
<li><a href="?pag=contact">contact</a></li>
</ul>
</div>
<h3></h3><h1>
Code (php)
1
2
3
2
3
<?php
echo str_replace("_", " ", $row["titel"])." ". str_replace("_", " ", $row_page1s["titel"]);
?>
echo str_replace("_", " ", $row["titel"])." ". str_replace("_", " ", $row_page1s["titel"]);
?>
</h1>
<div id="sidebar">
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
echo $row["tekst_links"];
//---------------page1---------------------
if ($pag == "page1s") {
$sql = "SELECT titel FROM page1s ORDER BY id DESC";
$resultaat = mysql_query($sql);
while ($record = mysql_fetch_object($resultaat)){
echo "<a href=\"?pag=page1s&art=".$record->titel."\">";
$titelstr = str_replace("_", " ", $record->titel);
if (strlen($titelstr) > 22){
$titelstr = substr($titelstr, 0, 18)."...";
}
echo $titelstr;
echo "</a><br>\n";
}
}
//---------------einde page1---------------------
//---------------audio---------------------
if ($pag == "audio") {
if (empty($aud)){
$sql = "SELECT titel FROM audio ORDER BY id DESC";
$resultaat = mysql_query($sql);
while ($record = mysql_fetch_object($resultaat)){
echo "<a href=\"?pag=audio&aud=".$record->titel."\">";
$titelstr = str_replace("_", " ", $record->titel);
if (strlen($titelstr) > 22){
$titelstr = substr($titelstr, 0, 18)."...";
}
echo $titelstr;
echo "</a><br>\n";
}
}
echo "<div align=\"right\"><br><b><a href=\"?pag=help\">Help</a> </b></div>";
}
//---------------einde audio---------------------
?>
echo $row["tekst_links"];
//---------------page1---------------------
if ($pag == "page1s") {
$sql = "SELECT titel FROM page1s ORDER BY id DESC";
$resultaat = mysql_query($sql);
while ($record = mysql_fetch_object($resultaat)){
echo "<a href=\"?pag=page1s&art=".$record->titel."\">";
$titelstr = str_replace("_", " ", $record->titel);
if (strlen($titelstr) > 22){
$titelstr = substr($titelstr, 0, 18)."...";
}
echo $titelstr;
echo "</a><br>\n";
}
}
//---------------einde page1---------------------
//---------------audio---------------------
if ($pag == "audio") {
if (empty($aud)){
$sql = "SELECT titel FROM audio ORDER BY id DESC";
$resultaat = mysql_query($sql);
while ($record = mysql_fetch_object($resultaat)){
echo "<a href=\"?pag=audio&aud=".$record->titel."\">";
$titelstr = str_replace("_", " ", $record->titel);
if (strlen($titelstr) > 22){
$titelstr = substr($titelstr, 0, 18)."...";
}
echo $titelstr;
echo "</a><br>\n";
}
}
echo "<div align=\"right\"><br><b><a href=\"?pag=help\">Help</a> </b></div>";
}
//---------------einde audio---------------------
?>
</div>
<div id="content">
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
echo $row["tekst"];
//---------------page1---------------------
if ($pag == "page1s") {
if (empty($art)){
$sql = "SELECT titel, omschrijving, counter FROM page1s ORDER BY id DESC";
$resultaat = mysql_query($sql);
while ($record = mysql_fetch_object($resultaat)){
echo "<b><a href=\"?pag=page1s&art=".$record->titel."\">".str_replace("_", " ", $record->titel)."</a></b>";
echo " <span class=\"gray\">views: ".$record->counter."</span><br />\n";
echo $record->omschrijving."<p></p>\n\n";
}
}
}
echo $row_page1s["tekst"];
//---------------einde page1---------------------
//---------------audio---------------------
if ($pag == "audio"){
$sql = "Select titel, omschrijving, counter, locatie FROM audio ORDER BY id DESC";
$resultaat = mysql_query($sql);
while ($record = mysql_fetch_object($resultaat)){
$file = filesize($record->locatie);
echo "<p><b><a href=\"?pag=audio&aud=";
echo $record->titel;
echo "\" target = \"blank\">".str_replace("_", " ", $record->titel)."</b></a> <span class=\"gray\">views: ".$record->counter." | size: ".round($file / (1024 * 1024), 2)."Mb</span><br>\n";
echo $record->omschrijving;
echo "</p>\n";
}
}
//---------------einde audio---------------------
if ($pag == "contact"){
include "include/contact.php";
}
?>
echo $row["tekst"];
//---------------page1---------------------
if ($pag == "page1s") {
if (empty($art)){
$sql = "SELECT titel, omschrijving, counter FROM page1s ORDER BY id DESC";
$resultaat = mysql_query($sql);
while ($record = mysql_fetch_object($resultaat)){
echo "<b><a href=\"?pag=page1s&art=".$record->titel."\">".str_replace("_", " ", $record->titel)."</a></b>";
echo " <span class=\"gray\">views: ".$record->counter."</span><br />\n";
echo $record->omschrijving."<p></p>\n\n";
}
}
}
echo $row_page1s["tekst"];
//---------------einde page1---------------------
//---------------audio---------------------
if ($pag == "audio"){
$sql = "Select titel, omschrijving, counter, locatie FROM audio ORDER BY id DESC";
$resultaat = mysql_query($sql);
while ($record = mysql_fetch_object($resultaat)){
$file = filesize($record->locatie);
echo "<p><b><a href=\"?pag=audio&aud=";
echo $record->titel;
echo "\" target = \"blank\">".str_replace("_", " ", $record->titel)."</b></a> <span class=\"gray\">views: ".$record->counter." | size: ".round($file / (1024 * 1024), 2)."Mb</span><br>\n";
echo $record->omschrijving;
echo "</p>\n";
}
}
//---------------einde audio---------------------
if ($pag == "contact"){
include "include/contact.php";
}
?>
</div>
<div id="footer"><a href="index.php">home</a> | <a href="?pag=contact">contact</a> | <a href="?pag=copyrights">© 2006 </a></div>
</div>
</body>
</html>
Verder is er geen sql injection mogenlijk zo te zien. En je gaat inspringen als je op hetzelfde nieveau zit. Waarom is dat?
Verder ziet het er naar mijn idee wel goed uit.
iig bedankt voor je reactie!
Zoiezo is dat ook niet goed. Dit moet zijn:
(je kunt dit soort fouten ondervangen door bovenaan je code error_reporting(E_ALL); te zetten, dan worden ook de waarschuwingen gegeven.)
Als je nu na bovenstaande controle de mysql_real_escape doet, dan is het goed:D
Bedankt voor de tip! ik heb het veranderd op m'n site!