Jump to content

Please help with cross-file variables (admin login options)


spInGoBlin

Recommended Posts

I'm trying to separate some users (with admin rights) from others, so that they can view and enter some data that will be hidden from others in many consequent windows. My login page goes like this:

if (isset($_POST['Submit']))
{
$username = $_POST['username'];
$password = $_POST['password'];

$result = mysql_query("Select * From admin where username='$username'",$link);
if(mysql_num_rows($result)>0)
{
$row = mysql_fetch_array($result, MYSQL_BOTH);
if($password == $row["password"])
{
$_SESSION['adminok'] = "ok";
$_SESSION['username'] = "username";
$_SESSION['password'] = "password";
header("Location: admin.php");
}
else {$msg = "Password incorrect";}
}
else {$msg = "Username incorrect";}
}
?>

There's a row in the SQL table (admin_rights) that's either 0 or 1 (true/false). how can I pass this variable on to another php page to filter out some rows from other SQL tables, depending on this variable? I reckon it should go something like this:

$clientsresult = mysql_query("Select * from clients",$link);
$numcli = mysql_num_rows($clientsresult);
$nc = 0;
while($clients = mysql_fetch_array($clientsresult, MYSQL_BOTH)){
[b]if ($isadmin) {[/b]
$nc++;
$client[$clients['client_ID']] = $clients['name'];
}
}

Well, this seems simple, but how shall I get the [b]$isadmin[/b] from login page? This is also simple I know :) but I'm having awsome trouble. Help please! Thanks.
Cant you just add a session in the login page? Or am i misreading too?

[code]if (isset($_POST['Submit']))
{
$username = $_POST['username'];
$password = $_POST['password'];

$result = mysql_query("Select * From admin where username='$username'",$link);
if(mysql_num_rows($result)>0)
{
$row = mysql_fetch_array($result, MYSQL_BOTH);
if($password == $row["password"])
{
$_SESSION['isadmin'] = "1"; // 1 = yes, 0 = no
$_SESSION['adminok'] = "ok";
$_SESSION['username'] = "username";
$_SESSION['password'] = "password";
header("Location: admin.php");
}
else {$msg = "Password incorrect";}
}
else {$msg = "Username incorrect";}
}
?>[/code]

then in the other page

[code]$clientsresult = mysql_query("Select * from clients",$link);
$numcli = mysql_num_rows($clientsresult);
$nc = 0;
while($clients = mysql_fetch_array($clientsresult, MYSQL_BOTH)){
if ($_SESSION['isadmin'] == "1") {
$nc++;
$client[$clients['client_ID']] = $clients['name'];
}
}[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.