[PHP] Simpel beveiligen wachtwoord & Sessie
Ik snap er nog niks van hoor ...
Geweldig, en dat binnen iets ruim 2 minuten.
Ik zeg:Motivatie
Ik zeg:Motivatie
Aarclay schreef:Ja geweldig of niet, als iemand me nou gewoon kan vertellen hoe ik een session start? Na een half uur klooien ben ik het nu ook zatGeweldig, en dat binnen iets ruim 2 minuten.

Als je nou iets als dit probeert..
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/session_start"]session_start[/URL][COLOR= #007700]();[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]ingelogd[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700]){[/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]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"pass"[/COLOR][COLOR= #007700]] !=[/COLOR] [COLOR= #DD0000]"admin"[/COLOR][COLOR= #007700]) {[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]"Wachtwoord klopt niet"[/COLOR][COLOR= #007700];
}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
[COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]ingelogd[/COLOR][COLOR= #007700]] =[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Je bent ingelogd, klik <a href="">hier</a>[/COLOR][COLOR= #007700];
}
}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]<div align="right">
<form action="" method="post">
<input name="pass" type="password" value="" size="9"><br />
<input type="submit" value="Log in">
</form>
</div> [/COLOR][COLOR= #007700];
}
}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Ingelogd gedeelte hier[/COLOR][COLOR= #007700];
}[/COLOR]
?> Dat wordt uitgelegd. Als jij geen motivatie erin stopt, dan zal je het nooit lukken.
Aarclay schreef:Ik was er mee bezig, ik had: $_SESSION[pass] = admin; dit al maar ik had het denk op de verkeerde plek...Dat wordt uitgelegd. Als jij geen motivatie erin stopt, dan zal je het nooit lukken.
session_start(); Zo start je een sessie

Jellesch schreef:Zo start je een sessiesession_start();

Nee goh, dat wist ik ook wel ...

Nickjexx schreef:Nee goh, dat wist ik ook wel ...Zo start je een sessieEerdere citaten tonen
Jellesch schreef:session_start();

Waarom vraag je het dan?

Thommity schreef:Als je nou iets als dit probeert..
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/session_start"]session_start[/URL][COLOR= #007700]();[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]ingelogd[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700]){[/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]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"pass"[/COLOR][COLOR= #007700]] !=[/COLOR] [COLOR= #DD0000]"admin"[/COLOR][COLOR= #007700]) {[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]"Wachtwoord klopt niet"[/COLOR][COLOR= #007700];
}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
[COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]ingelogd[/COLOR][COLOR= #007700]] =[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Je bent ingelogd, klik <a href="">hier</a>[/COLOR][COLOR= #007700];
}
}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]<div align="right">
<form action="" method="post">
<input name="pass" type="password" value="" size="9"><br />
<input type="submit" value="Log in">
</form>
</div> [/COLOR][COLOR= #007700];
}
}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Ingelogd gedeelte hier[/COLOR][COLOR= #007700];
}[/COLOR]
?> Thommity schreef:Waarom vraag je het dan?Nee goh, dat wist ik ook wel ...Eerdere citaten tonen
Nickjexx schreef:Zo start je een sessieEerdere citaten tonen
Jellesch schreef:session_start();

Thommity schreef:Als je nou iets als dit probeert..
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/session_start"]session_start[/URL][COLOR= #007700]();[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]ingelogd[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700]){[/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]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"pass"[/COLOR][COLOR= #007700]] !=[/COLOR] [COLOR= #DD0000]"admin"[/COLOR][COLOR= #007700]) {[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]"Wachtwoord klopt niet"[/COLOR][COLOR= #007700];
}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
[COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]ingelogd[/COLOR][COLOR= #007700]] =[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Je bent ingelogd, klik <a href="">hier</a>[/COLOR][COLOR= #007700];
}
}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]<div align="right">
<form action="" method="post">
<input name="pass" type="password" value="" size="9"><br />
<input type="submit" value="Log in">
</form>
</div> [/COLOR][COLOR= #007700];
}
}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Ingelogd gedeelte hier[/COLOR][COLOR= #007700];
}[/COLOR]
?> Omdat ik een andere functie bedoelde




Nickjexx schreef:Omdat ik een andere functie bedoeldeWaarom vraag je het dan?Eerdere citaten tonen
Thommity schreef:Nee goh, dat wist ik ook wel ...Eerdere citaten tonen
Nickjexx schreef:Zo start je een sessieEerdere citaten tonen
Jellesch schreef:session_start();Eerdere citaten tonen
Thommity schreef:Als je nou iets als dit probeert..[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/session_start"]session_start[/URL][COLOR= #007700]();[/COLOR] [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]ingelogd[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700]){[/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] [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"pass"[/COLOR][COLOR= #007700]] !=[/COLOR] [COLOR= #DD0000]"admin"[/COLOR][COLOR= #007700]) {[/COLOR] [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]"Wachtwoord klopt niet"[/COLOR][COLOR= #007700]; }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR] [COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]ingelogd[/COLOR][COLOR= #007700]] =[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700];[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Je bent ingelogd, klik <a href="">hier</a>[/COLOR][COLOR= #007700]; } }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR] [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]<div align="right"> <form action="" method="post"> <input name="pass" type="password" value="" size="9"><br /> <input type="submit" value="Log in"> </form> </div> [/COLOR][COLOR= #007700]; } }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Ingelogd gedeelte hier[/COLOR][COLOR= #007700]; }[/COLOR] ?>




Zeg het dan ook anders

"


"Nickjexx schreef:Nee goh, dat wist ik ook wel ...Zo start je een sessieEerdere citaten tonen
Jellesch schreef:session_start();

Daar vroeg je om ??
Jellesch schreef:Daar vroeg je om ??Nee goh, dat wist ik ook wel ...Eerdere citaten tonen
Nickjexx schreef:Zo start je een sessieEerdere citaten tonen
Jellesch schreef:session_start();
Je kon zelf toch ook kijken dat ik de functie al had


?toevoeging op 15 juni 2012, 18:41:02:
Volgende probleem, uitloggen werkt niet. Heb nu:
$_SESSION[ingelogd] = 0; en session_destroy();
toevoeging op 15 juni 2012, 18:47:11:
Uitloggen.php
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/session_destroy"]session_destroy[/URL][COLOR= #007700]();[/COLOR]
[URL="http://www.php.net/session_start"]session_start[/URL][COLOR= #007700]();[/COLOR]
[COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]ingelogd[/COLOR][COLOR= #007700]] =[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Je bent nu succesvol uitgelogd.<br />
Je wordt in 2 seconden doorgelinkt."[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<meta http-equiv="refresh" content="2;URL=index.php" />[/COLOR][COLOR= #007700];[/COLOR]
?> je gaat eerst een sessie proberen te verwijderen, terwijl de sessie-motor (session_start) niet geladen is..
En maak je opeens weer een sessie aan? Je wou toch uitloggen?
Nee, erg logisch ....
...
En die meta-tag hoort er niet.
En maak je opeens weer een sessie aan? Je wou toch uitloggen?
Nee, erg logisch ....
...En die meta-tag hoort er niet.