refreshing on logon?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

refreshing on logon?

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

where and how do you set/test the login-data?
Gleeb
Forum Commoner
Posts: 87
Joined: Tue May 13, 2003 7:01 am
Location: UK
Contact:

Post by Gleeb »

The page for header() has just what you're looking for (but not the drones) :)
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

)

Post 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&#1111;'admin'] == 1)
&#123;
	include 'admin/admenu.php';
&#125;
?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

but ..err.. of course you set $_SESSION['admin'] = $row['admin']; before if ($_SESSION['admin'] == 1) is tested? ;)
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

hmm, hehe

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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)?
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

yup

Post by irealms »

Code: Select all

<?
if ($userid && $password)
&#123;
  // 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&#1111;'approved'] == 1)
  &#123;
    // if they are in the database register the user id
    $valid_user = $userid;
    $_SESSION&#1111;'valid_user'] = $valid_user;
    $_SESSION&#1111;'pass'] = $_POST&#1111;'password'];
	$_SESSION&#1111;'id'] = $row&#1111;'id'];
	$_SESSION&#1111;'approved'] = $row&#1111;'approved'];
	$_SESSION&#1111;'officer'] = $row&#1111;'officer'];
	$_SESSION&#1111;'admin'] = $row&#1111;'admin'];
  &#125;
&#125;

  if ($_SESSION&#1111;'valid_user'])
  &#123;
    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>";
  &#125;
  
  else
  &#123;
	if (isset($userid) || $row&#1111;'approved'] == 0)
    &#123;
      // 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>";
      
    &#125;
	
	
    else 
    &#123;
      // they have not tried to log in yet or have logged out
      echo "<div class="log">You are not logged in.</div>";
    &#125;

    // 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 />";
    
  &#125;
?>
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.
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

(

Post by irealms »

it's still only doing it after a link is clicked.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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?
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

code

Post by irealms »

this is part of my index page

Code: Select all

<?
if ($_SESSION&#1111;'admin'] == 1)
&#123;
	include "admin/admenu.php";
&#125;
?>
<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.
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

redirect?

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

that's probably easier.
But why can't you put the login code before the admin-include block?
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

display

Post 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.
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

hmm

Post 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.
Post Reply