I have a small basic website with certain pages users can only view when they are logged in. There's only 1 username and password because the site is for just a few people and security isnt a major issue. Anyway, when the user types in the correct Username and password and submits, a cookie is set in the code and the page is reloaded. But it still shows the content as if the user werent logged in. When I press the sumbit button again or just click to another page, the content is shown correctly (more items in the navigation bar). I cant find out why it wont show the items the first time.
The top of the login page:
if (isset($_POST['reg'])){
if ($form_errors = validate_form()) {
show_form($form_errors);
} else {
logon();
}
} else {
show_form();
}
The content of the page (function show_form)
<?php
if( isset($_COOKIE['logedon'])){
echo '<p>You are now logged on</p>';
}
else{
//shows form containing: <input type="hidden" name="reg" value="1"/>
}
?>
and finally the logon() function
function logon(){
$expire= 60 * 60 * 24 * 10000 + time();
setcookie('logedon', true, $expire);
show_form();
}
So the cookie is set, the show_form function is called but still shows the form instead of the echo 'you are now logged on'. When I switch page or hit the submit button again, the echo is displayed. Why doesnt it do that the first time?
Please help!