Kleine Vragen Topic #3

Gestart doorStef2.514 reacties9.659 weergaven

2.515 berichten · pagina 67 van 168

Berichten
35.796
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
Hou er wel rekening mee dat mensen SQL injecties kunnen doen op die manier.
0
Berichten
6.037
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Lennard schreef:
Hou er wel rekening mee dat mensen SQL injecties kunnen doen op die manier.
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. yummie
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);
}

?>
0
Berichten
4.451
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
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
0
Berichten
6.037
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Bartv schreef:
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

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. confused
0
Berichten
4.451
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Als je echo $_SESSION[login]; doet, wat komt daaruit?
0
Berichten
6.037
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Bartv schreef:
Als je echo $_SESSION[login]; doet, wat komt daaruit?
jordyvc
0
Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Jordyvc schreef:
Eerdere citaten tonen
Bartv schreef:
Als je echo $_SESSION[login]; doet, wat komt daaruit?
jordyvc
Jordyvc schreef:
Eerdere citaten tonen
Bartv schreef:
Als je echo $_SESSION[login]; doet, wat komt daaruit?
jordyvc
Destory je de sessie wel?
0
Berichten
6.037
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Dylanh schreef:
Eerdere citaten tonen
Jordyvc schreef:
Eerdere citaten tonen
Bartv schreef:
Als je echo $_SESSION[login]; doet, wat komt daaruit?
jordyvc
Eerdere citaten tonen
Jordyvc schreef:
Eerdere citaten tonen
Bartv schreef:
Als je echo $_SESSION[login]; doet, wat komt daaruit?
jordyvc
Destory je de sessie wel?
Je moet toch niet uitloggen om iemand anders zijn profiel te kunnen zien? yummie
0
Berichten
4.451
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[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?
0
Berichten
6.037
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Bartv schreef:
[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?

Ja, dit werkt! biggrin
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Daar zit een mooie SQL-injection in. Controleer op je $_GET.
0
Berichten
35.796
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
Jordyvc 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. yummie
Leer het gewoon meteen goed aan zodat je snapt wanneer je wat moet beveiligen.
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Jordyvc schreef:
Eerdere citaten tonen
Lennard schreef:
Hou er wel rekening mee dat mensen SQL injecties kunnen doen op die manier.
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. yummie
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.
0
Berichten
421
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
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..
(Code)
Codeblok (voorbeeld.php):
1
2
3
4
5

0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Een enter als n bedoel je?
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren