Page 1 of 2
refreshing on logon?
Posted: Fri May 16, 2003 6:52 am
by irealms
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
Posted: Fri May 16, 2003 6:54 am
by volka
where and how do you set/test the login-data?
Posted: Fri May 16, 2003 6:55 am
by Gleeb
The page for
header() has just what you're looking for (but not the drones)

)
Posted: Fri May 16, 2003 7:00 am
by irealms
in the logon script 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'];
in the top of the index page i have
Code: Select all
<?
if ($_SESSIONї'admin'] == 1)
{
include 'admin/admenu.php';
}
?>
Posted: Fri May 16, 2003 7:02 am
by volka
but ..err.. of course you set
$_SESSION['admin'] = $row['admin']; before
if ($_SESSION['admin'] == 1) is tested?

hmm, hehe
Posted: Fri May 16, 2003 7:12 am
by irealms
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.
Posted: Fri May 16, 2003 7:19 am
by volka
hm, somewhere you do check wether a login attempt has been made, don't you? something like
Code: Select all
if (isset( $_POST['password']))
{
// login code here, including ...
$_SESSION['admin'] = $row['admin'];
}
why not put this block before
if ($_SESSION['admin'] == 1)?
yup
Posted: Fri May 16, 2003 8:05 am
by irealms
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 />";
}
?>
that my login i've tried using different sections of it before the admin check and it doesn't show up still until you link to something else, going to have to refresh i think.
(
Posted: Mon May 19, 2003 3:19 am
by irealms
it's still only doing it after a link is clicked.
Posted: Mon May 19, 2003 3:57 am
by volka
you've posted the part were
if ($_SESSION['valid_user'])
is checked but your problem (also?) is with
if ($_SESSION['admin'] == 1)
where's this code-block now?
code
Posted: Mon May 19, 2003 4:11 am
by irealms
this is part of my index page
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>
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.
redirect?
Posted: Mon May 19, 2003 4:21 am
by irealms
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.
Posted: Mon May 19, 2003 4:43 am
by volka
that's probably easier.
But why can't you put the login code before the admin-include block?
display
Posted: Mon May 19, 2003 4:53 am
by irealms
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.
hmm
Posted: Mon May 19, 2003 4:55 am
by irealms
how do i get it to redirect to another page when you click the logon button?
if i change the action it won't process the form.