inlogscript met md5 doet lastig
login.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
require_once 'inc/cfg.php';
require_once 'inc/users.class.php';
$u = new users;
if ($_POST['username'] != '') {
if (!$u->Login($_POST['username'], $_POST['pass'])) {
$error = 'Gebruikersnaam en / of wachtwoord onjuist.';
} else {
header('Location: beheer_index.php');
}
}
?>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<form action="" method="post">
<table class="list" align="center">
<?php if ($error != '' ) { ?>
<tr>
<td colspan="3">
<span style="color: red;"><?php print $error; ?></span>
</td>
</tr>
<?php } ?>
<tr>
<td>Username</td>
<td>:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input type="password" name="pass"></td>
</tr>
<tr>
<td colspan="3" align="right"><input type="submit" value="Login"></td>
</tr>
</table>
</form>
require_once 'inc/cfg.php';
require_once 'inc/users.class.php';
$u = new users;
if ($_POST['username'] != '') {
if (!$u->Login($_POST['username'], $_POST['pass'])) {
$error = 'Gebruikersnaam en / of wachtwoord onjuist.';
} else {
header('Location: beheer_index.php');
}
}
?>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<form action="" method="post">
<table class="list" align="center">
<?php if ($error != '' ) { ?>
<tr>
<td colspan="3">
<span style="color: red;"><?php print $error; ?></span>
</td>
</tr>
<?php } ?>
<tr>
<td>Username</td>
<td>:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input type="password" name="pass"></td>
</tr>
<tr>
<td colspan="3" align="right"><input type="submit" value="Login"></td>
</tr>
</table>
</form>
logoff.php
Code (php)
1
2
3
4
5
6
7
2
3
4
5
6
7
<?php
session_start();
unset($_SESSION['UserID']);
header('Location: beheer_index.php');
?>
session_start();
unset($_SESSION['UserID']);
header('Location: beheer_index.php');
?>
users.class.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
class users {
var $users;
function users() {
}
function getUsers() {
global $db, $dbPrefix;
return $db->get_results("SELECT * FROM ".$dbPrefix."users",ARRAY_A);
}
function getUser($id) {
global $db, $dbPrefix;
return $db->get_row("SELECT * FROM ".$dbPrefix."users WHERE id = '" . $id . "'",ARRAY_A);
}
function saveUser($p, $id = '') {
global $db, $dbPrefix;
if ($p['password'] != '' && $p['password2'] != '') {
$sqlPass = ", pass = '" . md5($p['password']) . "'";
}
if ($id == '') {
$db->query("INSERT INTO ".$dbPrefix."users SET username = '" . $p['username'] . "', level = '". $p['level'] ."'".$sqlPass);
} else {
$db->query("UPDATE ".$dbPrefix."users SET username = '".$p['username']."', level = '". $p['level'] ."'" . $sqlPass . " WHERE id = '" . $id . "'");
}
header("Location: users.php");
}
function delUser($id) {
global $db, $dbPrefix;
$db->query("DELETE FROM ".$dbPrefix."users WHERE id = '" . $id . "'");
header("Location: users.php");
}
function checkLogin() {
/*return*/ session_start();
if ($_SESSION['UserID'] == '') {
header('Location: login.php');
}
}
function logoff() {
session_start();
session_unset();
session_destroy();
header('Location: beheer_index.php');
}
function Login($username, $pass) {
global $db, $dbPrefix;
/*return*/ session_start();
/*return*/ $logCheck = $db->get_results("SELECT * FROM ".$dbPrefix."users WHERE username = '" . $username . "' AND pass = '" . md5($pass) . "'",ARRAY_A);
if ($db->num_rows() > 0) {
$_SESSION['UserID'] = $logCheck['id'];
$_SESSION['UserLevel'] = $logCheck['level'];
return true;
} else {
return false;
}
}
}
?>
class users {
var $users;
function users() {
}
function getUsers() {
global $db, $dbPrefix;
return $db->get_results("SELECT * FROM ".$dbPrefix."users",ARRAY_A);
}
function getUser($id) {
global $db, $dbPrefix;
return $db->get_row("SELECT * FROM ".$dbPrefix."users WHERE id = '" . $id . "'",ARRAY_A);
}
function saveUser($p, $id = '') {
global $db, $dbPrefix;
if ($p['password'] != '' && $p['password2'] != '') {
$sqlPass = ", pass = '" . md5($p['password']) . "'";
}
if ($id == '') {
$db->query("INSERT INTO ".$dbPrefix."users SET username = '" . $p['username'] . "', level = '". $p['level'] ."'".$sqlPass);
} else {
$db->query("UPDATE ".$dbPrefix."users SET username = '".$p['username']."', level = '". $p['level'] ."'" . $sqlPass . " WHERE id = '" . $id . "'");
}
header("Location: users.php");
}
function delUser($id) {
global $db, $dbPrefix;
$db->query("DELETE FROM ".$dbPrefix."users WHERE id = '" . $id . "'");
header("Location: users.php");
}
function checkLogin() {
/*return*/ session_start();
if ($_SESSION['UserID'] == '') {
header('Location: login.php');
}
}
function logoff() {
session_start();
session_unset();
session_destroy();
header('Location: beheer_index.php');
}
function Login($username, $pass) {
global $db, $dbPrefix;
/*return*/ session_start();
/*return*/ $logCheck = $db->get_results("SELECT * FROM ".$dbPrefix."users WHERE username = '" . $username . "' AND pass = '" . md5($pass) . "'",ARRAY_A);
if ($db->num_rows() > 0) {
$_SESSION['UserID'] = $logCheck['id'];
$_SESSION['UserLevel'] = $logCheck['level'];
return true;
} else {
return false;
}
}
}
?>
users.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
// Include global file
require_once 'inc/cfg.php';
require_once 'inc/users.class.php';
$u = new users;
$u->checkLogin();
if ($_GET['del'] != '') {
$u->delUser($_GET['del']);
}
$users = $u->getUsers();
print '<table class="list">';
print '<tr>';
print '<td>Naam</td>';
print '<td colspan="2"></td>';
print '</tr>';
foreach($users as $user) {
print '<tr>';
print '<td>'.$user['username'].'</td>';
print '<td>
<a href="edit_user.php?id=' . $user['id'] . '"><img src="../templates/front/icons/edit.png" border="0"></a></td>';
if ($_SESSION['UserID'] <= 15) {
print '<td>
<a href="?del=' . $user['id'] . '" onclick="return confirm(\'Are you sure you want to delete?\')"><img src="../templates/front/icons/del.png" border="0"></a></td>';
}
print '</tr>';
}
print '</table><br>';
print '<a href="edit_user.php"><img src="../templates/front/icons/plus.gif" border="0" width="20"></a>';
?>
// Include global file
require_once 'inc/cfg.php';
require_once 'inc/users.class.php';
$u = new users;
$u->checkLogin();
if ($_GET['del'] != '') {
$u->delUser($_GET['del']);
}
$users = $u->getUsers();
print '<table class="list">';
print '<tr>';
print '<td>Naam</td>';
print '<td colspan="2"></td>';
print '</tr>';
foreach($users as $user) {
print '<tr>';
print '<td>'.$user['username'].'</td>';
print '<td>
<a href="edit_user.php?id=' . $user['id'] . '"><img src="../templates/front/icons/edit.png" border="0"></a></td>';
if ($_SESSION['UserID'] <= 15) {
print '<td>
<a href="?del=' . $user['id'] . '" onclick="return confirm(\'Are you sure you want to delete?\')"><img src="../templates/front/icons/del.png" border="0"></a></td>';
}
print '</tr>';
}
print '</table><br>';
print '<a href="edit_user.php"><img src="../templates/front/icons/plus.gif" border="0" width="20"></a>';
?>
Hoewel het bij de ene hoster dus werkt krijg ik bij een andere de volgende foutmelding:
Fatal error: Call to a member function get_results() on a non-object in /../../../beheer/inc/users.class.php on line 65
Ik heb het onder andere geprobeerd om het op te lossen door één of meerdere "return" te plaatsen in users.class.php. In sommige gevallen heb ik dan niet meer de foutmelding, maar controleert het script ook niet meer de input. Dus alle invoer bij "gebruikersnaam" en "wachtwoord" wordt ok bevonden. Dit is zeker niet de bedoeling. De hoster bij wie het niet werkt biedt geen ondersteuning, dus vandaar mijn bericht hier. Wie kan mij zeggen waarom het script waarschijnlijk bij de ene hoster wel goed werkt en bij een andere niet?
- Aar -:
Gelieve in het vervolg bij code de [code][/code]-tags gebruiken.
Alvast bedankt!
Alvast bedankt!
Toevoeging op 04/04/2014 01:00:17:
Ok. Zo ziet het er inderdaad beter uit.
Gewijzigd op 04/04/2014 00:57:40 door - Ariën -
Kijk eens of het connecten met de database wel goed gaat, wanr $db is kennelijk leeg
Dit was inderdaad een deel van het probleem. Dank voor de tip.