Mijn PHP kunsten

Gestart doorKlaasie6 reacties47 weergaven

7 berichten · pagina 1 van 1

Klaasie

Lid · Topicstarter

Berichten
5.498
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Beste One2xs leden,

Ik ben een tijdje geleden gestopt met programmeren en zou nu graag de draad weer willen oppakken smile!

Het laatste werk wat ik heb gemaakt voordat ik ben gestopt is dit:

[COLOR= #0000BB]<?php[/COLOR] [COLOR= #FF8000]//PHP starten.
/**
 * @author Klaas Yntema
 * @copyright 2012
 */[/COLOR]
[URL="http://www.php.net/include"]include[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]includes/config.php[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//Config bestand inporteren.[/COLOR]

[COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]] =[/COLOR] [URL="http://www.php.net/strtolower"]strtolower[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]]);[/COLOR] [COLOR= #FF8000]//Gebruikersnaam veranderen in kleine letters.[/COLOR]
[COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]email[/COLOR][COLOR= #007700]] =[/COLOR] [URL="http://www.php.net/strtolower"]strtolower[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]email[/COLOR][COLOR= #007700]]);[/COLOR] [COLOR= #FF8000]//Email adres veranderen in kleine letters.[/COLOR]
[COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]] =[/COLOR] htmlentities[COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]]);[/COLOR] [COLOR= #FF8000]//HTML uit de gebruikersnaam filteren.[/COLOR]

[COLOR= #0000BB]$EmailCheckQuery[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM leden WHERE email="[/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]email[/COLOR][COLOR= #007700]]).[/COLOR][COLOR= #DD0000]" LIMIT 1"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR] [COLOR= #FF8000]//Query om te checken of het email adres al bestaat aanmaken.[/COLOR]
[COLOR= #0000BB]$NaamCheckQuery[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM leden WHERE gebruikersnaam="[/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]]).[/COLOR][COLOR= #DD0000]" LIMIT 1"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR] [COLOR= #FF8000]//Query om te checken of gebruikersnaam al bestaat aanmaken.[/COLOR]
[COLOR= #0000BB]$IPCheckQuery[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM leden WHERE IP="[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REMOTE_ADDR[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR] [COLOR= #FF8000]//Query om het aantal IPs te checken.[/COLOR]


[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REQUEST_METHOD[/COLOR][COLOR= #007700]]==[/COLOR][COLOR= #DD0000]"POST"[/COLOR][COLOR= #007700]) {[/COLOR] [COLOR= #FF8000]//Checken of er iets is verzonden met POST data[/COLOR]


    [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$IPCheckQuery[/COLOR][COLOR= #007700]) ==[/COLOR] [COLOR= #0000BB]3[/COLOR][COLOR= #007700]) {[/COLOR] [COLOR= #FF8000]//Doormiddel van de query hierboven checken of er 3 Ips zijn.[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<font color=red>Er zijn maximaal 3 accounts per IP toegestaan!</font><br />"[/COLOR][COLOR= #007700];    
    }[/COLOR]
    
    [URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/strlen"]strlen[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]]) <[/COLOR] [COLOR= #0000BB]3[/COLOR][COLOR= #007700]) {[/COLOR] [COLOR= #FF8000]//Checken of de gebruikersnaam minimaal 3 tekens bevat.[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<font color=red>De gebruikersnaam moet minimaal 3 tekens bevatten!</font><br />"[/COLOR][COLOR= #007700];
    }[/COLOR]
    
    [URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/strlen"]strlen[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]]) >[/COLOR] [COLOR= #0000BB]12[/COLOR][COLOR= #007700]) {[/COLOR] [COLOR= #FF8000]//Checken of de gebruikersnaam maximaal 12 tekens bevat.[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<font color=red>De gebruikersnaam mag maximaal 12 tekens bevatten!</font><br />"[/COLOR][COLOR= #007700];
    }[/COLOR]
    
    [URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700](![/COLOR][URL="http://www.php.net/preg_match"]preg_match[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]/^[a-z0-9]+$/i[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]]) ) {[/COLOR] [COLOR= #FF8000]//Checken of er tekens in de gebruikersnaam zitten die niet zijn toegestaan.[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<font color=red>De gebruikersnaam bevat tekens die niet zijn toegestaan!</font><br />"[/COLOR][COLOR= #007700];    
    }[/COLOR]
    
    [URL="http://www.php.net/elseif"]elseif[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$NaamCheckQuery[/COLOR][COLOR= #007700]) ==[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700]) {[/COLOR] [COLOR= #FF8000]//Doormiddel van de query hierboven checken of de gebruikersnaam al in gebruik is.[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<font color=red>Er is al een account aan gemaakt met deze gebruikersnaam!</font><br />"[/COLOR][COLOR= #007700];    
    }[/COLOR]
    
    [URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/empty"]empty[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]email[/COLOR][COLOR= #007700]])) {[/COLOR] [COLOR= #FF8000]//Checken of er een email adres is ingevuld.[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<font color=red>Je hebt geen email adres ingevuld!</font><br />"[/COLOR][COLOR= #007700];        
    }[/COLOR]
    
    [URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700](![/COLOR]filter_var[COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]email[/COLOR][COLOR= #007700]],[/COLOR] FILTER_VALIDATE_EMAIL[COLOR= #007700])) {[/COLOR] [COLOR= #FF8000]//Checken of het email adres geldig is.[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<font color=red>Het ingevoerde email adres is niet geldig!</font><br />"[/COLOR][COLOR= #007700];
    }[/COLOR]
    
    [URL="http://www.php.net/elseif"]elseif[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$EmailCheckQuery[/COLOR][COLOR= #007700]) ==[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700]) {[/COLOR] [COLOR= #FF8000]//Doormiddel van de query hierboven checken of het email adres al in gebruik is.[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<font color=red>Er is al een account aan gemaakt met dit email adres!</font><br />"[/COLOR][COLOR= #007700];    
    }[/COLOR]
    
    [URL="http://www.php.net/elseif"]elseif[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]wachtwoord[/COLOR][COLOR= #007700]] !=[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]wachtwoord2[/COLOR][COLOR= #007700]]) {[/COLOR] [COLOR= #FF8000]//Checken of de wachtwoorden met elkaar overeen komen.[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<font color=red>De wachtwoorden komen niet overeen met elkaar!</font><br />"[/COLOR][COLOR= #007700];    
    }[/COLOR]
    
    [URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/strlen"]strlen[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]wachtwoord[/COLOR][COLOR= #007700]]) <[/COLOR] [COLOR= #0000BB]4[/COLOR][COLOR= #007700]) {[/COLOR] [COLOR= #FF8000]//Checken of het wachtwoord minimaal 4 tekens bevat.[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<font color=red>Het wachtwoord moet minimaal 4 tekens bevatten!</font><br />"[/COLOR][COLOR= #007700];
    }[/COLOR]
    
    
    [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
    
    
        [COLOR= #0000BB]$wachtwoord[/COLOR][COLOR= #007700]=[/COLOR]hash[COLOR= #007700]([/COLOR]sha512[COLOR= #007700],[/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]wachtwoord[/COLOR][COLOR= #007700]]);[/COLOR] [COLOR= #FF8000]//Wachtwoord crypten met sha512[/COLOR]
        [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"INSERT INTO leden (gebruikersnaam,wachtwoord,email,rang,ban,IP,registreerdatum) VALUES ("[/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]]) .[/COLOR] [COLOR= #DD0000]","[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$wachtwoord[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]","[/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]email[/COLOR][COLOR= #007700]]) .[/COLOR] [COLOR= #DD0000]",Lid,0,"[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REMOTE_ADDR[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]",NOW())"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
        
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<font color=green>Je bent succesvol geregistreerd!</font><br />"[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]//Query om lid in database te zetten uitvoeren + melding geven dat je bent aangemeld.[/COLOR]
    
    
    [COLOR= #007700]}
}[/COLOR]
?>
<form action= method=post>
      Gebruikersnaam: <input type=text name=gebruikersnaam /><br />
      Email adres: <input type=text name=email /><br />
      Wachtwoord: <input type=password name=wachtwoord /><br />
      Wachtwoord nogmaals: <input type=password name=wachtwoord2 /><br />
      <input type=submit value=Aanmelden!/>
      </form>


Zouden jullie mij misschien wat tips kunnen geven over dingen die ik kan veranderen om het veiliger/beter te maken, zo leer ik misschien weer wat bij smile!

Alvast bedankt,

Klaas.

Het is niet de bedoeling dat jullie dit script gaan gebruiken, doe dit A.U.B ook niet!
0
Berichten
20.364
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik vind dat alles bij elkaar geplakt is, geen enters ofzo en ook te veel comments. Form in een echo is ook onnodig.
0
Klaasie

Lid · Topicstarter

Berichten
5.498
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Shahiem schreef:
Ik vind dat alles bij elkaar geplakt is, geen enters ofzo en ook te veel comments. Form in een echo is ook onnodig.
De comments zijn inderdaad een beetje overbodig, normaal doe ik dit eigenlijk vrijwel nooit winkIk zal even wat enters toevoegen om wat meer overzicht te krijgen. Heb nu wat enters toegevoegd en ik zie nu dat het veel overzichtelijker is redface!

Bedankt voor je tips!
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Ik mis goede foutafhandeling op je query. Die() valt hier NIET onder.

En is ook een oud fossiel qua HTML. Weg ermee, op naar CSS

Lijn 8 t/m 14 horen na je POST-controle te komen.
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Niet echt goed gescript.

[COLOR= #0000BB]<?php
$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]] =[/COLOR] [URL="http://www.php.net/strtolower"]strtolower[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]]);[/COLOR] [COLOR= #FF8000]//Gebruikersnaam veranderen in kleine letters.[/COLOR]
[COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]email[/COLOR][COLOR= #007700]] =[/COLOR] [URL="http://www.php.net/strtolower"]strtolower[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]email[/COLOR][COLOR= #007700]]);[/COLOR] [COLOR= #FF8000]//Email adres veranderen in kleine letters.[/COLOR]
[COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]] =[/COLOR] htmlentities[COLOR= #007700]([/COLOR][COLOR= #0000BB]$_[/COLOR]
?>


Als een lid naar die pagina gaat zonder een post header zal je errors krijgen omdat bv $_POST[gebruikersnaam] niet bestaat
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Raaoul schreef:
Niet echt goed gescript.

[COLOR= #0000BB]<?php
$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]] =[/COLOR] [URL="http://www.php.net/strtolower"]strtolower[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]]);[/COLOR] [COLOR= #FF8000]//Gebruikersnaam veranderen in kleine letters.[/COLOR]
[COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]email[/COLOR][COLOR= #007700]] =[/COLOR] [URL="http://www.php.net/strtolower"]strtolower[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]email[/COLOR][COLOR= #007700]]);[/COLOR] [COLOR= #FF8000]//Email adres veranderen in kleine letters.[/COLOR]
[COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]] =[/COLOR] htmlentities[COLOR= #007700]([/COLOR][COLOR= #0000BB]$_[/COLOR]
?>
Als een lid naar die pagina gaat zonder een post header zal je errors krijgen omdat bv $_POST[gebruikersnaam] niet bestaat

display_errors(0)


wss emo
0
Berichten
5.897
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Antonn schreef:
Eerdere citaten tonen
Raaoul schreef:
Niet echt goed gescript.
[COLOR= #0000BB]<?php
$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]] =[/COLOR] [URL="http://www.php.net/strtolower"]strtolower[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]]);[/COLOR] [COLOR= #FF8000]//Gebruikersnaam veranderen in kleine letters.[/COLOR]
[COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]email[/COLOR][COLOR= #007700]] =[/COLOR] [URL="http://www.php.net/strtolower"]strtolower[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]email[/COLOR][COLOR= #007700]]);[/COLOR] [COLOR= #FF8000]//Email adres veranderen in kleine letters.[/COLOR]
[COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]] =[/COLOR] htmlentities[COLOR= #007700]([/COLOR][COLOR= #0000BB]$_[/COLOR]
?>


Als een lid naar die pagina gaat zonder een post header zal je errors krijgen omdat bv $_POST[gebruikersnaam] niet bestaat
display_errors(0)


wss emo
Hij kan het evengoed gewoon een beetje verzetten emo
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