I want to show my logout form (containing logout button) when user is logged in and hide otherwise. I use this code:
<?php
if(isset($_SESSION['logged_in'])) {
//show logout form
?>
Problem in steps:
- User gets on page and fills info in login form
- Login form is submitted (controlled with hidden input), on button click
- Login input value is compared with database values
- If input values are correct; $_SESSION['logged_in'] = true
- echo 'You are logged in!'
- The page gets refreshed (automatically done after form submit); 'You are logged' in is shown, but the logout form is not
- Now I have to refresh the page myself; The logout form is shown
Same thing happens on logging out. Logout form (and login form) only hides/shows when I refresh the page myself.
Any possible solutions?