The webpage consist of a header, which is included, a left navigation which is included, a content area which is included and a footer which is included.
In the navigation, there is a list of links. When I click a link, I update the content area by switching to another included file. So far no problem.
I have two forms, one log in and one log out form. I have put the forms in variables, because I want to be able to hide the log in form when the user logs in and instead show a log out button:
$my_form=‘<form id=“form1” action=“test.php” method=“get”>
User name:
<input type=“text” name="username " />
Password:
<input type=“text” name=“password” />
<br />
<input type=“submit” id=“knapp” name=“knapp” value=“Log in” />’;
$log_out=‘<form name=“form2” action=“test.php” method=“get”>
<input type=“submit” value=“Log out” />
</form>’
When the user puts in his name and the correct password I use unset() to hide the log in form and echo to show a another form, a logout form:
$my_password=“secret”;
if ($my_password== $_GET[‘password’])
{
echo "You are logged in;
unset($my_form);
echo $ log_out;
}
This will hide the log in form and show the logout form. When I click the log out button, the log in form pops up again. No problem so far. Now to the problem. Let’s say I log in. The log out button pops up on the main page. Let’s say I also click a link in the navigation area:
<li><a href=“?var_music=music”>Music</a></li>
If I click a link in the navigation area, a new included file is shown in the content area and the log in form replaces the log out button. That’s the problem. The browser does not know that I want the logout button to stay at the top of the page.
I know it’s a session problem. I know that I should put this in the main page above the html tag.
<?php
session_start();
?>
But what else do I have to do to make the connection work? I know how to “transfer” values between pages using get and post, but here I am not trying to show something on another page. I want to keep the values on the main page, here test.php. And I want to use the get method.