for the login link use the following code:
<a href="/login.php?accesscheck=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">Login</a>
for the logout link, use:
<a href="/logout.php?accesscheck=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">Login</a>
on the login page, make sure the action of the form uses the following code:
action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?><?php echo (isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != "")?"?".htmlspecialchars($_SERVER["QUERY_STRING"]):""; ?>"
on the logout page, add an access restriction to restrict access to only allow logged in users, make sure the access restriction code is after the clear session code on the logout page.
that should do the trick.