Heey allemaal!
Ik heb een functie gemaakt in PHP die moet checken of er een sessie/cookie is aangemaakt, en als dat niet zo is word er geen toegang verleend tot het admingedeelte en als er wel een sessie/cookie is dan krijg je wel toegang.
Helaas werkt het volgende niet:
Dit is het logingedeelte:
Oja, het is maar met één gebruiker, vandaar dat ik die gegevens gewoon in een string zet in niet in de database.
Ik hoop dat iemand me kan helpen!
Alvast bedankt,
Groetjes Jos
Ik heb een functie gemaakt in PHP die moet checken of er een sessie/cookie is aangemaakt, en als dat niet zo is word er geen toegang verleend tot het admingedeelte en als er wel een sessie/cookie is dan krijg je wel toegang.
Helaas werkt het volgende niet:
[COLOR= #0000BB]<?php
$account_naam[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]admin[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$account_wachtwoord[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]test123[/COLOR][COLOR= #007700];
function[/COLOR] checkLogin[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]$account_naam[/COLOR][COLOR= #007700]]) &&[/COLOR] [URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_COOKIE[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]AdminSessie[/COLOR][COLOR= #007700]]))
{[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]U heeft niet de rechten om deze pagina te bekijken, u kunt <a href="login.php">hier</a> inloggen.[/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]Welkom op het beheerpaneel!<br /><br />Kies hieronder uit een van de mogelijkheden om iets op de website te plaatsen:[/COLOR][COLOR= #007700];
}
}[/COLOR]
?> Dit is het logingedeelte:
[COLOR= #0000BB]<?php[/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]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]Inloggen[/COLOR][COLOR= #007700]])){[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]naam[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #0000BB]$account_naam[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]wachtwoord[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #0000BB]$account_wachtwoord[/COLOR][COLOR= #007700]){[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<div class="goed">U bent succesvol ingelogd, u word zo doorgestuurd naar het beheerpaneel.</div>[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]$account_naam[/COLOR][COLOR= #007700]];[/COLOR]
[URL="http://www.php.net/setcookie"]setcookie[/URL][COLOR= #007700]([/COLOR]AdminSessie[COLOR= #007700],[/COLOR] [COLOR= #0000BB]$account_naam[/COLOR][COLOR= #007700],[/COLOR] [URL="http://www.php.net/time"]time[/URL][COLOR= #007700]()+[/COLOR][COLOR= #0000BB]3600[/COLOR][COLOR= #007700]*[/COLOR][COLOR= #0000BB]24[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"refresh: 3; url=admin.php"[/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 class="fout">U heeft onjuiste gegevens ingevuld, probeer het nog een keer!</div>[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"refresh: 3;"[/COLOR][COLOR= #007700]);
}
}[/COLOR]
?>
<div style="margin-left: auto; margin-right: auto; padding-top: 0px;">
<center>
<form method="post" action="">
<table border="0">
<tr>
<td>Gebruikersnaam:</td>
<td>
<input type="text" name="naam" size="25px">
</td>
</tr>
<tr>
<td>Wachtwoord</td>
<td><input type="password" name="wachtwoord" size="25px"></td>
</tr>
</table>
<input type="submit" value="inloggen" name="Inloggen">
</form>
</center>
</div>
?> Oja, het is maar met één gebruiker, vandaar dat ik die gegevens gewoon in een string zet in niet in de database.
Ik hoop dat iemand me kan helpen!
Alvast bedankt,
Groetjes Jos


