David_Powers wrote https://forums.adobe.com/people/Nancy+OShea , osgood_, and BenPleysier are all right: Dreamweaver's PHP server behaviors are no longer fit for purpose. Do not use them. If you like my style of teaching, but can't afford a subscription to lynda.com, try to get hold of a copy of my PHP Solutions, 3rd Edition, published by Apress. It's not expensive, and you can probably find a second-hand copy. I've not been active in these forums for several months for personal reasons. I do intend to come back eventually, but not just yet. |
Nice to see you're still around David and hope whatever is keeping you away eventually resolves itself in a positive way.
It would'nt be difficult to direct an Admin user to an Admin Section of the website and a Non-Admin-User to a different section of the website based on what access level they have been assigned in the database.
Using mysqli below. Querying a database with the name 'users' and a table within that database with the name 'users'. In the users table there are 3 fields - username, password and userlevel where you set the userlevel to 1 for an admin and leave it blank for a non admin.
Of couse this is just a simple example and principal of using mysqli, checking username and password are correct and what level of access the user has and sending them to the appopriate section. In the instance below the password in NOT encrypted in the database but it should be which would bring a new set of problems when checking the password against the form field input. If you are using php 5.5 or greater you can use the php password_verify function, PHP: password_verify - Manual which would be reasonably easy to incorporate into the code.
Of course this would also have a knock on effect as you would need to remove any DW server behaviours you have used on the internal pages which effect the login being verified and replace that with a simple bit of php code that redirects back to the login page if $_SESSION['username'] is not set. That is set once the username and password has been checked against those held in the database and are verified as correct - $_SESSION['username'] = $username;
<?php session_start() ?>
<?php
// connect to database
$conn = new mysqli('localhost' , 'root' , 'root' , 'users'); ?>
<?php
// Query database for username and password
if(isset($_POST['submit'])) {
$username = $conn->real_escape_string((trim($_POST['username']));
$sql = 'SELECT * FROM users';
$result = $conn->query($sql) or die($conn->error);
while ($row = $result->fetch_assoc()) {
if ($row['username'] == $username && $row['userlevel'] == 1 && $row['password'] == trim($_POST['password'])) {
$_SESSION['username'] = $username;
// Redirect to admin users to specific page if login successful
header('Location: http://www.bbc.co.uk');
}
elseif ($row['username'] == $username && $row['password'] == trim($_POST['password'])) {
$_SESSION['username'] = $username;
// Redirect non-admin users to specific page if login successful
header('Location: http://www.itv.co.uk');
}
else {
// If username and password don't match then asign a message to a variable
$response = "Sorry you do not have permission to access this website";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Secure Login</title>
</head>
<body>
<h1>Login Username</h1>
<?php
if(isset($response)) {
echo $response;
}
?>
<form id="login" name="login" method="post" action="">
<label for="username">Username</label><br />
<input type="text" name="username" id="username" value=""/><br />
<label for="password">Password</label><br />
<input type="text" name="password" id="password" value=""/><br />
<input type="submit" name="submit" id="submit" value="Submit" />
</form>
</body>
</html>