Hou er wel rekening mee dat mensen SQL injecties kunnen doen op die manier.
Kleine Vragen Topic #3
Lennard schreef:Ik ga, wanneer alles bijna klaar is er helemaal overgaan samen met iemand om alles te beveiligen. Als ik dat tussendoor zou doen vergeet ik toch hier en daar iets en kijk ik er niet meer op terug als het klaar is.Hou er wel rekening mee dat mensen SQL injecties kunnen doen op die manier.

Ik heb nog een vraagje, mijn bedoeling is als bv. profile.php?name=jordyvc dat die iets bepaalt moet laten zien omdat je ingelogt bent als jordyvc. En als je hetzelfde doet en nog steeds ingelogt bent met Jordyvc maar naar een andere gebruiker gaat bv. profile.php?name=lol dat die iets anders moet laten zien omdat jij dat niet bent.
Ik probeer met sessions te werken maar het wilt niet lukken, ik doe iets verkeerd.
Mijn code:
Codeblok (voorbeeld.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
include (dbconf.php);
if (isset($_SESSION[login])) {
$name = $_GET[name];
$Query = mysqli_query($mysqli, "SELECT * FROM users WHERE username=".$_GET[name]."");
$Fetch = mysqli_fetch_assoc($Query);
if(!isset($_GET[name])) {
echo No username given!;
} else if(isset($_GET[name]) == $_SESSION[login]) { // Als je dit zelf bent
echo Hello, ;
echo $Fetch[first_name];
echo this is your profile.
Edit profile Edit account settings;
} else { // Als je naar ene andere gebruiker gaat
echo Profile of;
echo $Fetch[first_name];
echo $Fetch[last_name];
}
} else {
header(Location: index.php);
}
?>
1. Waarom defineer je $name als je die toch niet gebruikt?
2. Check eerst of je $_GET[name] gebruikt en daarna pas de query, dat is beter
3. Als het goed is is $_SESSION[login] je id dus zo:
Codeblok (voorbeeld.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
include (dbconf.php);
if (isset($_SESSION[login]))
{
if(!isset($_GET[name]))
{
echo No username given!;
}
else
{
$Query = mysqli_query($mysqli, "SELECT * FROM users WHERE username=".$_GET[name]."");
$Fetch = mysqli_fetch_assoc($Query);
if(isset($Fetch[id]) == $_SESSION[login])
{ // Als je dit zelf bent
echo Hello, ;
echo $Fetch[first_name];
echo this is your profile.
Edit profile Edit account settings;
}
else
{ // Als je naar ene andere gebruiker gaat
echo Profile of;
echo $Fetch[first_name];
echo $Fetch[last_name];
}
}
}
else
{
header(Location: index.php);
}
?>
zo zou ik het doen, tenminste, snel dan.
Ik zou ook nog een check inbouwen of de gebruiker uberhaupt bestaat, maar dat laat ik aan jou over
2. Check eerst of je $_GET[name] gebruikt en daarna pas de query, dat is beter
3. Als het goed is is $_SESSION[login] je id dus zo:
Codeblok (voorbeeld.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
include (dbconf.php);
if (isset($_SESSION[login]))
{
if(!isset($_GET[name]))
{
echo No username given!;
}
else
{
$Query = mysqli_query($mysqli, "SELECT * FROM users WHERE username=".$_GET[name]."");
$Fetch = mysqli_fetch_assoc($Query);
if(isset($Fetch[id]) == $_SESSION[login])
{ // Als je dit zelf bent
echo Hello, ;
echo $Fetch[first_name];
echo this is your profile.
Edit profile Edit account settings;
}
else
{ // Als je naar ene andere gebruiker gaat
echo Profile of;
echo $Fetch[first_name];
echo $Fetch[last_name];
}
}
}
else
{
header(Location: index.php);
}
?>
zo zou ik het doen, tenminste, snel dan.
Ik zou ook nog een check inbouwen of de gebruiker uberhaupt bestaat, maar dat laat ik aan jou over
Bartv schreef:11. Waarom defineer je $name als je die toch niet gebruikt?
2. Check eerst of je $_GET[name] gebruikt en daarna pas de query, dat is beter
3. Als het goed is is $_SESSION[login] je id dus zo:
Codeblok (voorbeeld.php):
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
include (dbconf.php);
if (isset($_SESSION[login]))
{
if(!isset($_GET[name]))
{
echo No username given!;
}
else
{
$Query = mysqli_query($mysqli, "SELECT * FROM users WHERE username=".$_GET[name]."");
$Fetch = mysqli_fetch_assoc($Query);
if(isset($Fetch[id]) == $_SESSION[login])
{ // Als je dit zelf bent
echo Hello, ;
echo $Fetch[first_name];
echo this is your profile.
Edit profile Edit account settings;
}
else
{ // Als je naar ene andere gebruiker gaat
echo Profile of;
echo $Fetch[first_name];
echo $Fetch[last_name];
}
}
}
else
{
header(Location: index.php);
}
?>
zo zou ik het doen, tenminste, snel dan.
Ik zou ook nog een check inbouwen of de gebruiker uberhaupt bestaat, maar dat laat ik aan jou over
Het werkt niet ik ben ingelogd als Jordyvc als ik dan naar profile.pgp?name=jordyvc ga dan is dat juist, dan krijg ik "this is your profile.." maar als ik ingelogd blijf en naar profile.php?name=lol ga dan zegt die hetzelfde maar dan veranderd de naam gewoon.

Als je echo $_SESSION[login]; doet, wat komt daaruit?
Bartv schreef:jordyvcAls je echo $_SESSION[login]; doet, wat komt daaruit?
Jordyvc schreef:jordyvcEerdere citaten tonen
Bartv schreef:Als je echo $_SESSION[login]; doet, wat komt daaruit?
Jordyvc schreef:Destory je de sessie wel?jordyvcEerdere citaten tonen
Bartv schreef:Als je echo $_SESSION[login]; doet, wat komt daaruit?
Dylanh schreef:Je moet toch niet uitloggen om iemand anders zijn profiel te kunnen zien?Eerdere citaten tonen
Jordyvc schreef:jordyvcEerdere citaten tonen
Bartv schreef:Als je echo $_SESSION[login]; doet, wat komt daaruit?Destory je de sessie wel?Eerdere citaten tonen
Jordyvc schreef:jordyvcEerdere citaten tonen
Bartv schreef:Als je echo $_SESSION[login]; doet, wat komt daaruit?

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/include"]include[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]dbconf.php[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]login[/COLOR][COLOR= #007700]]))
{[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]name[/COLOR][COLOR= #007700]]))
{[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]No username given![/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL]
[COLOR= #007700]{[/COLOR]
[COLOR= #0000BB]$Query[/COLOR] [COLOR= #007700]=[/COLOR] mysqli_query[COLOR= #007700]([/COLOR][COLOR= #0000BB]$mysqli[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"SELECT * FROM users WHERE username="[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]name[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$Fetch[/COLOR] [COLOR= #007700]=[/COLOR] mysqli_fetch_assoc[COLOR= #007700]([/COLOR][COLOR= #0000BB]$Query[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$Fetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]name[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]login[/COLOR][COLOR= #007700]])
{[/COLOR] [COLOR= #FF8000]// Als je dit zelf bent[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Hello, [/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$Fetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]first_name[/COLOR][COLOR= #007700]];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000] this is your profile. <br /><a href="#">Edit profile</a> <a href="#">Edit account settings</a>[/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL]
[COLOR= #007700]{[/COLOR] [COLOR= #FF8000]// Als je naar ene andere gebruiker gaat[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Profile of[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$Fetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]first_name[/COLOR][COLOR= #007700]];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$Fetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]last_name[/COLOR][COLOR= #007700]];
}
}
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL]
[COLOR= #007700]{[/COLOR]
[URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Location: index.php[/COLOR][COLOR= #007700]);
}[/COLOR]
?> Zo?
Bartv schreef:Zo?[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/include"]include[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]dbconf.php[/COLOR][COLOR= #007700]);[/COLOR] [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]login[/COLOR][COLOR= #007700]])) {[/COLOR] [URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]name[/COLOR][COLOR= #007700]])) {[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]No username given![/COLOR][COLOR= #007700]; }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR] [COLOR= #0000BB]$Query[/COLOR] [COLOR= #007700]=[/COLOR] mysqli_query[COLOR= #007700]([/COLOR][COLOR= #0000BB]$mysqli[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"SELECT * FROM users WHERE username="[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]name[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #0000BB]$Fetch[/COLOR] [COLOR= #007700]=[/COLOR] mysqli_fetch_assoc[COLOR= #007700]([/COLOR][COLOR= #0000BB]$Query[/COLOR][COLOR= #007700]);[/COLOR] [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$Fetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]name[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]login[/COLOR][COLOR= #007700]]) {[/COLOR] [COLOR= #FF8000]// Als je dit zelf bent[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Hello, [/COLOR][COLOR= #007700];[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$Fetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]first_name[/COLOR][COLOR= #007700]];[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000] this is your profile. <br /><a href="#">Edit profile</a> <a href="#">Edit account settings</a>[/COLOR][COLOR= #007700]; }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR] [COLOR= #FF8000]// Als je naar ene andere gebruiker gaat[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Profile of[/COLOR][COLOR= #007700];[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$Fetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]first_name[/COLOR][COLOR= #007700]];[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$Fetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]last_name[/COLOR][COLOR= #007700]]; } } }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR] [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Location: index.php[/COLOR][COLOR= #007700]); }[/COLOR] ?>
Ja, dit werkt!

Daar zit een mooie SQL-injection in. Controleer op je $_GET.
Jordyvc schreef:Leer het gewoon meteen goed aan zodat je snapt wanneer je wat moet beveiligen.Ik ga, wanneer alles bijna klaar is er helemaal overgaan samen met iemand om alles te beveiligen. Als ik dat tussendoor zou doen vergeet ik toch hier en daar iets en kijk ik er niet meer op terug als het klaar is.
Jordyvc schreef:Vreemde manier.... Ik zou het andersom zeggen: Dat je alles meteen beveiligd, i.p.v. later. De kans is groter dat je anders alsnog steken laat vallen.Ik ga, wanneer alles bijna klaar is er helemaal overgaan samen met iemand om alles te beveiligen. Als ik dat tussendoor zou doen vergeet ik toch hier en daar iets en kijk ik er niet meer op terug als het klaar is.Eerdere citaten tonen
Lennard schreef:Hou er wel rekening mee dat mensen SQL injecties kunnen doen op die manier.
Ik heb deze js code maar als er een enter in een bericht staat dan werkt het niet meer..
Hoe los ik dit op?
Ik heb al gezocht op google maar kan niet echt iets vinden.. 1
2
3
4
5
Hoe los ik dit op?
Ik heb al gezocht op google maar kan niet echt iets vinden..
(Code)
Codeblok (voorbeeld.php):
2
3
4
5
Een enter als n bedoel je?