(CMS) login, headers already sent probleem
"Warning: Cannot modify header information - headers already sent by (output started at J:\wwwroot\cms\includes\systemcomponent.php:24) in J:\wwwroot\cms\includes\sentry.php on line 112"
Ik blijf dan ook gewoon het inlog scherm zien en word niet doorgestuurd. Nou heb ik beetje zitten proberen om het eruit te krijgen, maar ik kom er niet uit, ik hoop dat jullie me kunnen helpen. Ik zal hieronder even de desbetreffende scripts posten.
Alvast bedankt,
Bastiaan
systemcomponent
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
sentry
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
////////////////////////////////////////////////////////////////////////////////////////
// Class: sentry
// Purpose: Control access to pages
///////////////////////////////////////////////////////////////////////////////////////
class sentry
{
var $loggedin = false; // Boolean to store whether the user is logged in
var $userdata; // Array to contain user's data
function sentry()
{
session_start();
header("Cache-control: private");
}
//======================================================================================
// Log out, destroy session
function logout()
{
unset($this->userdata);
session_destroy();
return true;
}
//======================================================================================
// Log in, and either redirect to goodRedirect or badRedirect depending on success
function checkLogin($user = '', $pass = '', $group = 10, $goodRedirect = '', $badRedirect =
'')
{
// Include database and validation classes, and create objects
require_once ('dbconnector.php');
require_once ('validator.php');
$validate = new validator();
$loginConnector = new dbconnector();
// If user is already logged in then check credentials
if ($_SESSION['user'] && $_SESSION['pass'])
{
// Validate session data
if (!$validate->validateTextOnly($_SESSION['user']))
{
return false;
}
if (!$validate->validateTextOnly($_SESSION['pass']))
{
return false;
}
$getUser = $loginConnector->query("SELECT * FROM cmsusers WHERE user = '" . $_SESSION['user'] .
"' AND pass = '" . $_SESSION['pass'] . "' AND thegroup <= " . $group .
' AND enabled = 1');
if ($loginConnector->getNumRows($getUser) > 0)
{
// Existing user ok, continue
if ($goodRedirect != '')
{
header("Location: " . $goodRedirect . "?" . strip_tags(session_id()));
}
return true;
}
else
{
// Existing user not ok, logout
$this->logout();
return false;
}
// User isn't logged in, check credentials
}
else
{
// Validate input
if (!$validate->validateTextOnly($user))
{
return false;
}
if (!$validate->validateTextOnly($pass))
{
return false;
}
// Look up user in DB
$getUser = $loginConnector->query("SELECT * FROM cmsusers WHERE user = '$user' AND pass = PASSWORD('$pass') AND thegroup <= $group AND enabled = 1");
$this->userdata = $loginConnector->fetchArray($getUser);
if ($loginConnector->getNumRows($getUser) > 0)
{
// Login OK, store session details
// Log in
$_SESSION["user"] = $user;
$_SESSION["pass"] = $this->userdata['pass'];
$_SESSION["thegroup"] = $this->userdata['thegroup'];
if ($goodRedirect)
{
header("Location: " . $goodRedirect . "?" . strip_tags(session_id()));
}
return true;
}
else
{
// Login BAD
unset($this->userdata);
if ($badRedirect)
{
header("Location:" . $badRedirect);
}
return false;
}
}
}
}
?>
////////////////////////////////////////////////////////////////////////////////////////
// Class: sentry
// Purpose: Control access to pages
///////////////////////////////////////////////////////////////////////////////////////
class sentry
{
var $loggedin = false; // Boolean to store whether the user is logged in
var $userdata; // Array to contain user's data
function sentry()
{
session_start();
header("Cache-control: private");
}
//======================================================================================
// Log out, destroy session
function logout()
{
unset($this->userdata);
session_destroy();
return true;
}
//======================================================================================
// Log in, and either redirect to goodRedirect or badRedirect depending on success
function checkLogin($user = '', $pass = '', $group = 10, $goodRedirect = '', $badRedirect =
'')
{
// Include database and validation classes, and create objects
require_once ('dbconnector.php');
require_once ('validator.php');
$validate = new validator();
$loginConnector = new dbconnector();
// If user is already logged in then check credentials
if ($_SESSION['user'] && $_SESSION['pass'])
{
// Validate session data
if (!$validate->validateTextOnly($_SESSION['user']))
{
return false;
}
if (!$validate->validateTextOnly($_SESSION['pass']))
{
return false;
}
$getUser = $loginConnector->query("SELECT * FROM cmsusers WHERE user = '" . $_SESSION['user'] .
"' AND pass = '" . $_SESSION['pass'] . "' AND thegroup <= " . $group .
' AND enabled = 1');
if ($loginConnector->getNumRows($getUser) > 0)
{
// Existing user ok, continue
if ($goodRedirect != '')
{
header("Location: " . $goodRedirect . "?" . strip_tags(session_id()));
}
return true;
}
else
{
// Existing user not ok, logout
$this->logout();
return false;
}
// User isn't logged in, check credentials
}
else
{
// Validate input
if (!$validate->validateTextOnly($user))
{
return false;
}
if (!$validate->validateTextOnly($pass))
{
return false;
}
// Look up user in DB
$getUser = $loginConnector->query("SELECT * FROM cmsusers WHERE user = '$user' AND pass = PASSWORD('$pass') AND thegroup <= $group AND enabled = 1");
$this->userdata = $loginConnector->fetchArray($getUser);
if ($loginConnector->getNumRows($getUser) > 0)
{
// Login OK, store session details
// Log in
$_SESSION["user"] = $user;
$_SESSION["pass"] = $this->userdata['pass'];
$_SESSION["thegroup"] = $this->userdata['thegroup'];
if ($goodRedirect)
{
header("Location: " . $goodRedirect . "?" . strip_tags(session_id()));
}
return true;
}
else
{
// Login BAD
unset($this->userdata);
if ($badRedirect)
{
header("Location:" . $badRedirect);
}
return false;
}
}
}
}
?>
Gewijzigd op 01/01/1970 01:00:00 door Bastiaan
Gewijzigd op 01/01/1970 01:00:00 door Bastiaan
Je gebruikt een paar keer de functie header() en je gebruikt session_start. Beiden moeten aangeroepen voordat er verder ook maar iets naar de browser verstuurd wordt. Een spatie is al te veel.
require_once ('dbconnector.php');
require_once ('validator.php');
Dat is niet handig om in een classe op te nemen. Je wilt binnen een classe niet afhankelijk zijn van gegevens die buiten de classe staan maar niet als input worden opgegeven. Dit zal altijd fout gaan. Zet de gegevens in de classe of geef ze als parameter op.
Maar ik zie niks wat naar mijn browser wordt gestuurd, dus daarom snap ik de fout niet.
J:\wwwroot\cms\includes\systemcomponent.php:24) in 24 is het nummer van de regel waar output staat. Bijv een spatie na de sluittag??
JAAAAAAAA, dankje dat is het! Nu werkt ie! Eindelijk na lang zoeken!