refreshing on logon?
Moderator: General Moderators
refreshing on logon?
as all my pages are called into the index i need to refresh index when someone logs on. the reason for this is if you are an admin an extra menu appears , this menu doesn't appear until you click another link after your logged on as the logon area is the only bt that changes at first. Any ideas?
the page is http://www.irealms.co.uk/crimson
log test
user test
the page is http://www.irealms.co.uk/crimson
log test
user test
The page for header() has just what you're looking for (but not the drones) 
)
in the logon script i have
in the top of the index page i have
Code: Select all
$valid_user = $userid;
$_SESSIONї'valid_user'] = $valid_user;
$_SESSIONї'pass'] = $_POSTї'password'];
$_SESSIONї'id'] = $rowї'id'];
$_SESSIONї'approved'] = $rowї'approved'];
$_SESSIONї'officer'] = $rowї'officer'];
$_SESSIONї'admin'] = $rowї'admin'];Code: Select all
<?
if ($_SESSIONї'admin'] == 1)
{
include 'admin/admenu.php';
}
?>hmm, hehe
well the code that check it is before the place the login script is called in, this is fine at first as the variable for admin doesn't need to be set until the user logs in. It works if you login then click the home link as this refreshes the whole page.
I see your point not sure how to get round it though.
I see your point not sure how to get round it though.
hm, somewhere you do check wether a login attempt has been made, don't you? something likewhy not put this block before if ($_SESSION['admin'] == 1)?
Code: Select all
if (isset( $_POST['password']))
{
// login code here, including ...
$_SESSION['admin'] = $row['admin'];
}yup
Code: Select all
<?
if ($userid && $password)
{
// if the user has just tried to log in
$query = "select * from users "
."where username='$userid' "
." and passwd='$password' ";
$result = mysql_query($query, $db_conn);
$row = mysql_fetch_assoc($result);
if (mysql_num_rows($result) >0 && $rowї'approved'] == 1)
{
// if they are in the database register the user id
$valid_user = $userid;
$_SESSIONї'valid_user'] = $valid_user;
$_SESSIONї'pass'] = $_POSTї'password'];
$_SESSIONї'id'] = $rowї'id'];
$_SESSIONї'approved'] = $rowї'approved'];
$_SESSIONї'officer'] = $rowї'officer'];
$_SESSIONї'admin'] = $rowї'admin'];
}
}
if ($_SESSIONї'valid_user'])
{
echo "<table><tr><td><div class="log">You are logged in as: $valid_user</div></td></tr></table>";
echo "<table align="right"><tr><td><a href="index.php?log=logout">Log out</a></td></tr>";
echo "<tr><td><a href="index.php?log=change">Change password</a></td></tr></table>";
}
else
{
if (isset($userid) || $rowї'approved'] == 0)
{
// if they've tried and failed to log in
echo "<div class="log">Could not log you in</div>";
echo "<a href="index.php?log=forgot" />Forgotten your<br />password?</a></div>";
}
else
{
// they have not tried to log in yet or have logged out
echo "<div class="log">You are not logged in.</div>";
}
// provide form to log in
echo "<div class="log"><form method=post action="index.php?log=">";
echo "<table class="log">";
echo "<tr><td>Userid:</td></tr>";
echo "<tr><td><input type=text name=userid style="font-size:10px;border:solid 1px;"></td></tr>";
echo "<tr><td>Password:</td></tr>";
echo "<tr><td><input type=password name=password style="font-size:10px;border:solid 1px;"></td></tr>";
echo "<tr><td colspan=2 align=center>";
echo "<input type=image src="buttons\login.gif" value="Log in"></td></tr>";
echo "</table></form>";
echo "<a href="index.php?page=reg" />Register here.</a><br />";
}
?>code
this is part of my index page
the code that check for the $_SESSION['admin'] variable is at the top where i want the admin menu to appear and then further down is the area where the login "authmain.php" (the file i posted above) is included.
Code: Select all
<?
if ($_SESSIONї'admin'] == 1)
{
include "admin/admenu.php";
}
?>
<table align="left" width="160" cellpadding="0" cellspacing="0" border="0">
<tr>
<td height="220" width="160">
<?
if ($log=="") include "authmain.php";
if ($log=="logout") include "logout.php";
if ($log=="change") include "changepass.php";
if ($log=="1") include "changepass.php";
if ($log=="forgot") include "forgot.php";
?>
</td>redirect?
would it be easier to just have the user shown a 'your are now logged in' page and then redirected back to the main page? This would have refreshed index and therefore have passed the session variable.
display
don't want it to display in the same place , if i stick the code up there then it will.
take a look at http://www.irealms.co.uk/crimson
admin will appear over the top of the page, login is below and to the left.
take a look at http://www.irealms.co.uk/crimson
admin will appear over the top of the page, login is below and to the left.