PDA

View Full Version : make login button disappear when logged in, and logout button disappear when not logged in.


Josh
11-26-2010, 08:25 PM
Hi,

the title pretty much explains it,

how would I go about getting the login button to disappear when a user logs in, and also the logout button to disppear when the user isn't logged in.

Thanks,

Josh

Josh
11-27-2010, 08:10 PM
Please can somebody point me in the right direction or give me some links so I can figure this out.

Sites a bit un-professional if it displays these buttons when they're not needed.

Thanks,

Josh

Corrosive
11-28-2010, 09:56 AM
You could could echo/print out the code for the log in stuff dependent on a check for a session. You are checking for a session for users anyway (to see if they are logged in or not) so it makes sense to use an if statement to show the form or a 'welcome user' message instead.

Josh
12-13-2010, 10:38 AM
Back to try and get this working,

at the moment this is whats in my dreamweaver template

<p align="right"><a href="../includes/loginaction.php">Sign In</a> <a href="../register.php">Register </a><a href="../logout.php">Logout</a> <a href="../member.php">My Account</a>


so it's basically just text linking to the relevant pages.

I'm assuming that it's on the template page that I need to add some code to enable the "sign in" button to disappear when Logged in. But I have no idea what code to add to make this happen. Need the same to happen for the logout button too but I cnt seem to find anywhere that tells me.

Would appreciate any help,

Thanks,

Josh

jmichae3
12-14-2010, 01:38 AM
login.php's login is controlled by a GET parameter.


<?php
$started = session_start();
if ($started
&& !isset($_SESSION['loginstatus'])
&& !isset($_SESSION['userid'])
&& (!isset($_GET['login']) || 'out' == $_GET['login'])
) {
$_SESSION['loginstatus'] = 'not logged in';
//note that true/false doesn't work with sessions
$_SESSION['username'] = '';
}
if ($started
&& 'mypassword' == $_POST['password']
&& 'myusername' == $_POST['username']
&& 'in' == $_GET['login']) {
$_SESSION['loginstatus'] = 'logged in';
$_SESSION['username'] = $_POST['username'];
}
?><!DOCTYPE HTML>
<html>
<head>
<title>login page</title>
</head>
<body>
<?php
if ($started
<?php
$started = session_start();
if ($started && 'logged in' == $_SESSION['loginstatus']) {
//we are logged in, so show logout
?>
<p><a href="login.php?login=out">logout</a></p>
<?php
} else {
//we are logged out, so show login
?>
<form>
<label for="username">uid:</label><input id="username" type="text" name="username" maxlength="20" /><br />
<label for="username">pwd:</label><input type="text" id="password" name="password" maxlength="20" />
<input type="submit">
</form></p>
<?php
}
?>