In a nutshell what I am trying to do is protect certain pages of a site. The way I attempted to do this was by way of this include file accesscontrol.php. Any page I wish to protect, I would simply add <?php include 'accesscontrol.php';>
The problem is that a session is not being created because of an undefined index (error I keep getting).
I wanted the code to create session variable based on email_ID and pwd_ID and Usergroup. (Usergroup is a value pre determined in the database set to either visitor or admin.)
How can I pull Usergroup up when the user logs in to add it to the session ID?
accesscontrol.php below.
Code:
<?php // accesscontrol.php
include_once 'common.php';
include_once 'db.php';
session_start();
//At this point, the user's login details should be available whether they were just submitted from a login form
//(in the $_POST array) or stored in the user's session (in the $_SESSION array).
//The script pulls the login credentials out of either the $_POST or the $_SESSION array:
$uid = isset($_POST['email_ID']) ? $_POST['email_ID'] : $_SESSION['email_ID'];
$pwd = isset($_POST['pwd_ID']) ? $_POST['pwd_ID'] : $_SESSION['pwd_ID'];
$ugroup = isset($_POST['Usergroup']) ? $_POST['Usergroup'] : $_SESSION['Usergroup'];
if(!isset($uid)) {
?>
<!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN"
" <html xmlns=" <head>
<title> Please Log In for Access </title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1> Login Required </h1>
<p>You must log in to access this area of the site. If you are
not a registered user, <a href="signup.php">click here</a>
to sign up for instant access!</p>
<p><form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="log_frm" id="log_frm">
User ID: <input name="email_ID" type="text" id="email_ID" size="8" />
Password: <input name="pwd_ID" type="password" id="pwd_ID" SIZE="8" />
<input type="submit" value="Log in" />
</form></p>
</body>
</html>
<?php
exit;
}
$_SESSION['email_ID'] = $uid;
$_SESSION['pwd_ID'] = $pwd;
$_SESSION['Usergroup'] = $ugroup;
dbConnect("db");
$sql = "SELECT * FROM users WHERE
Email = '$uid' AND Password = PASSWORD('$pwd')";
$result = mysql_query($sql);
if (!$result) {
error('A database error occurred while checking your '.
'login details.\\nIfhis error persists, please '.
'contact blah@blah.com.');
}
if (mysql_num_rows($result) == 0) {
unset($_SESSION['email_ID']);
unset($_SESSION['pwd_ID']);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
" <html xmlns=" <head>
<title> Access Denied </title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1> Access Denied </h1>
<p>You do not have permission to access these pages.<br>
Click <a href="self_service.php">here</a> to return to<br>
the self service point.</p>
</body>
</html>
<?php
exit;
}
$username = mysql_result($result,0,'Firstname');
?>
[/color red]
I keep getting these errors:
Notice: Undefined index: email_ID in c:\easyphp1-7\ on line 10
Notice: Undefined index: pwd_ID in c:\easyphp1-7\ on line 11
Notice: Undefined index: Usergroup in c:\easyphp1-7\ on line 12
[/color red]
The problem is that a session is not being created because of an undefined index (error I keep getting).
I wanted the code to create session variable based on email_ID and pwd_ID and Usergroup. (Usergroup is a value pre determined in the database set to either visitor or admin.)
How can I pull Usergroup up when the user logs in to add it to the session ID?
accesscontrol.php below.
Code:
<?php // accesscontrol.php
include_once 'common.php';
include_once 'db.php';
session_start();
//At this point, the user's login details should be available whether they were just submitted from a login form
//(in the $_POST array) or stored in the user's session (in the $_SESSION array).
//The script pulls the login credentials out of either the $_POST or the $_SESSION array:
$uid = isset($_POST['email_ID']) ? $_POST['email_ID'] : $_SESSION['email_ID'];
$pwd = isset($_POST['pwd_ID']) ? $_POST['pwd_ID'] : $_SESSION['pwd_ID'];
$ugroup = isset($_POST['Usergroup']) ? $_POST['Usergroup'] : $_SESSION['Usergroup'];
if(!isset($uid)) {
?>
<!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN"
" <html xmlns=" <head>
<title> Please Log In for Access </title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1> Login Required </h1>
<p>You must log in to access this area of the site. If you are
not a registered user, <a href="signup.php">click here</a>
to sign up for instant access!</p>
<p><form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="log_frm" id="log_frm">
User ID: <input name="email_ID" type="text" id="email_ID" size="8" />
Password: <input name="pwd_ID" type="password" id="pwd_ID" SIZE="8" />
<input type="submit" value="Log in" />
</form></p>
</body>
</html>
<?php
exit;
}
$_SESSION['email_ID'] = $uid;
$_SESSION['pwd_ID'] = $pwd;
$_SESSION['Usergroup'] = $ugroup;
dbConnect("db");
$sql = "SELECT * FROM users WHERE
Email = '$uid' AND Password = PASSWORD('$pwd')";
$result = mysql_query($sql);
if (!$result) {
error('A database error occurred while checking your '.
'login details.\\nIfhis error persists, please '.
'contact blah@blah.com.');
}
if (mysql_num_rows($result) == 0) {
unset($_SESSION['email_ID']);
unset($_SESSION['pwd_ID']);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
" <html xmlns=" <head>
<title> Access Denied </title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1> Access Denied </h1>
<p>You do not have permission to access these pages.<br>
Click <a href="self_service.php">here</a> to return to<br>
the self service point.</p>
</body>
</html>
<?php
exit;
}
$username = mysql_result($result,0,'Firstname');
?>
[/color red]
I keep getting these errors:
Notice: Undefined index: email_ID in c:\easyphp1-7\ on line 10
Notice: Undefined index: pwd_ID in c:\easyphp1-7\ on line 11
Notice: Undefined index: Usergroup in c:\easyphp1-7\ on line 12
[/color red]