By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 816 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

two levels of access login script

P: n/a
I have a fairly simple login in script and I need to make it have two
levels of access not one. can anyone help me with this? The script is
below:

<?php
// we must never forget to start the session
session_start();
$errorMessage = '';
if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) {
include 'config.php';
include 'opendb.php';
$userId = $_POST['txtUserId'];
$password = $_POST['txtPassword'];
// check if the user id and password combination exist in database
$sql = "SELECT user_id
FROM auth_user
WHERE user_id = '$userId'
AND user_password = '$password'";
$result = mysql_query($sql)
or die('Query failed. ' . mysql_error());
if (mysql_num_rows($result) == 1) {
// the user id and password match,
// set the session
$_SESSION['db_is_logged_in'] = true;
// after login we move to the main page
header('Location: list_pages.php');
exit;
} else {
$errorMessage = 'Sorry, wrong user id / password';
}
include 'closedb.php';
}
?>
<html>
<head>
<title>Login</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body>
<?php
if ($errorMessage != '') {
?>
<p align="center"><strong><font color="#990000"><?php echo
$errorMessage; ?></
font></strong></p>
<?php
}
?>
<form method="post" name="frmLogin" id="frmLogin" class="box">
<table width="400" border="1" align="center" cellpadding="2"
cellspacing="2">
<tr>
<td colspan="2"><b>Login</b></td>
</tr>
<tr>
<td width="150">User Id</td>
<td><input name="txtUserId" type="text" id="txtUserId" class="box"></
td>
</tr>
<tr>
<td width="150">Password</td>
<td><input name="txtPassword" type="password" id="txtPassword"
class="box"></td>
</tr>
<tr>
<td width="150">&nbsp;</td>
<td><input type="submit" name="btnLogin" value="Login" class="box"></
td>
</tr>
</table>
</form>
</body>
</html>

thank you in advanced

God bless
jason

May 31 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On May 30, 10:40 pm, jsd219 <i...@musiclanerecording.comwrote:
I have a fairly simple login in script and I need to make it have two
levels of access not one. can anyone help me with this? The script is
below:

<?php
// we must never forget to start the session
session_start();
$errorMessage = '';
if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) {
include 'config.php';
include 'opendb.php';
$userId = $_POST['txtUserId'];
$password = $_POST['txtPassword'];
// check if the user id and password combination exist in database
$sql = "SELECT user_id
FROM auth_user
WHERE user_id = '$userId'
AND user_password = '$password'";
$result = mysql_query($sql)
or die('Query failed. ' . mysql_error());
if (mysql_num_rows($result) == 1) {
// the user id and password match,
// set the session
$_SESSION['db_is_logged_in'] = true;
// after login we move to the main page
header('Location: list_pages.php');
exit;} else {

$errorMessage = 'Sorry, wrong user id / password';}

include 'closedb.php';}

?>
<html>
<head>
<title>Login</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body>
<?php
if ($errorMessage != '') {
?>
<p align="center"><strong><font color="#990000"><?php echo
$errorMessage; ?></
font></strong></p>
<?php}

?>
<form method="post" name="frmLogin" id="frmLogin" class="box">
<table width="400" border="1" align="center" cellpadding="2"
cellspacing="2">
<tr>
<td colspan="2"><b>Login</b></td>
</tr>
<tr>
<td width="150">User Id</td>
<td><input name="txtUserId" type="text" id="txtUserId" class="box"></
td>
</tr>
<tr>
<td width="150">Password</td>
<td><input name="txtPassword" type="password" id="txtPassword"
class="box"></td>
</tr>
<tr>
<td width="150">&nbsp;</td>
<td><input type="submit" name="btnLogin" value="Login" class="box"></
td>
</tr>
</table>
</form>
</body>
</html>

thank you in advanced

God bless
jason
Actually a better way of putting it is, I have two hard coded user ids
and passwords with an aditional field called level. for the sake of
this explanation lets call them.
user_id - abc password - 123 level - 1
user-id - xyz password - 456 level - 2

I have two separate admin pages called list_pages.php and
list_pages1.php

I need a login to allow people that sign in with user_id abc to be
able to access list_pages.php and users that sign in with user_id xyz
to be able to access list_pages1.php

can anyone help, Please. i am quite a novice.

God bless
jason

May 31 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.