Hallo liebe Community,
ich bekomme bei meinem Script folgende Fehlermeldung:
|
PHP-Quelltext
|
1
|
Warning: Cannot modify header information - headers already sent by (output started at C:UsersLukasxammp2xampphtdocsvalidate.class.php:219) in C:UsersLukasxammp2xampphtdocsvalidate.php on line 23
|
Dies bedeutet, dass die header Information in validate.php nicht gesendet werden kann, da davor in validate.class.php bereits der output gestartet hat. Evenutell habe ich in validate.class.php irgendwo ein kleines Zeichen vergessen, welches bewirkt, dass das Script einen output hat. Zumindest suche ich seit ca 2 Tagen nach dem Fehler und ich glaube ich bin einfach zu befangen von diesem Projekt, um den Fehler zu finden. Ich wäre euch sehr verbunden, wenn ihr nochmal drüber schauen könntet.
Hier die validate.php:
|
PHP-Quelltext
|
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
|
<?php
session_start();
//lädt Fehlerbehandlungsskript und Validierungsklasse
require_once ('error_handler.php');
require_once ('validate.class.php');
//erzeugt neues validator-Objekt
$validator = new Validate();
//liest Validierungstyp (PHP oder AJAX?)
$validationType = '';
if (isset($_GET['validationType']))
{
$validationType = $_GET['validationType'];
}
//AJAX- oder PHP-Validierung?
if ($validationType == 'php')
{
//die PHP-Validierung übernimmt die Methode ValidatePHP: Sie gibt die
//Seite zurück, auf die der Besucher geleitet wird(zu allok.php, wenn
//alle Daten gültig sind, oder ansonsten wieder zu index.php)
header("Location:" . $validator->ValidatePHP());
}
else
{
//Die AJAX_Validierung übernimmt die Methode ValidateAjax. Aus den
//Ergebnissen wird ein XML-Dokument geformt und an den Client gesant.
$response =
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' .
'<response>' .
'<result>' .
$validator->ValidateAJAX($_POST['inputValue'], $_POST['fieldID']) .
'</result>' .
'<fieldid>' .
$_POST['fieldID'] .
'</fieldid>' .
'</response>';
//generiert Antwort
if(ob_get_length()) ob_clean();
header('Content-Type: text/xml');
echo $response;
}
?>
|
und hier die validate.class.php:
|
PHP-Quelltext
|
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
<?php
//lädt Fehlerbehandlung und Datenbankkonfiguration
require_once ('config.php');
//die Klasse unterstützt AJAX- und PHP-Webformularvalidierung
class Validate
{
//gespeicherte Datenbankverbindung
private $mMysqli;
//Konstruktor öffnet Datenbankverbing
function __construct()
{
$this->mMysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
}
//Destrukt schließt Datenbankverbindung
function __destruct()
{
$this->mMysqli->close();
}
//untersützt AJAX-Validierung, prüft einen einzelnen Wert
public function ValidateAJAX($inputValue, $fieldID)
{
switch($fieldID) {
//prüft, welches Feld validier wrid und übernimmt Validierung
case 'txtUsername':
return $this->validateUserName($inputValue);
break;
case 'txtName':
return $this->validateName($inputValue);
break;
case 'selGender':
return $this->validateGender($inputValue);
break;
case 'selBthMonth':
return $this->validateBrithMonth($inputValue);
break;
case 'txtBthDay':
return $this->validateBirthDay($inputValue);
break;
case 'txtBthYear':
return $this->validateBirthYear($inputValue);
break;
case 'txtEmail':
return $this->validateEmail($inputValue);
break;
case 'txtPhone':
return $this->validatePhone($inputValue);
break;
case 'chkReadTerms':
return $this->validateReadTerms($inputValue);
break;
}
}
//validiert alle Formularfelder bei der Übermittlung
public function ValidatePHP()
{
//Fehler-Flag, wird 1, wenn Fehler gefunden werden
$errorsExist = 0;
//löscht das Erros-Session-Flag
if (isset($_SESSION['errors']))
unset($_SESSION['errors']);
//standardmäßig werden alle Felder für gultig gehalten
$_SESSION['errors']['txtUsername'] = 'hidden';
$_SESSION['errors']['txtNam'] = 'hidden';
$_SESSION['errors']['selGender'] = 'hidden';
$_SESSION['errors']['selBthMonth'] = 'hidden';
$_SESSION['errors']['txtBthDay'] = 'hidden';
$_SESSION['errors']['txtBthYear'] = 'hidden';
$_SESSION['errors']['txtEmail'] = 'hidden';
$_SESSION['errors']['txtPhone'] = 'hidden';
$_SESSION['errors']['chkReadTerms'] = 'hidden';
if(!$this->validateUserName($_POST['txtUsername']))
{
$_SESSION['errors']['txtUsername'] = 'error';
$errorsExist = 1;
}
if(!$this->validateName($_POST['txtName']))
{
$_SESSION['errors']['txtName'] = 'error';
$errorsExist = 1;
}
if(!$this->validateBrithMonth($_POST['selBthMonth']))
{
$_SESSION['errors']['selBthMonth'] = 'error';
$errorsExist = 1;
}
if(!$this->validateBirthDay($_POST['txtBthDay']))
{
$_SESSION['errors']['txtBthDay'] = 'error';
$errorsExist = 1;
}
if(!$this->validateGender($_POST['selGender']))
{
$_SESSION['errors']['selGender'] = 'error';
$errorsExist = 1;
}
if (!$this->validateBirthYear($_POST['selBthMonth'] . '#' . $_POST['txtBthDay'] . '#' . $_POST['txtBthYear']))
{
$_SESSION['errors']['txtBthYear'] = 'error';
$errorsExist = 1;
}
if(!$this->validateEmail($_POST['txtEmail']))
{
$_SESSION['errors']['txtEmail'] = 'error';
$errorsExist = 1;
}
if(!$this->validatePhone($_POST['txtPhone']))
{
$_SESSION['errors']['txtPhone'] = 'error';
$errorsExist = 1;
}
if(!isset($_POST['chkReadTerms']) || !$this->validateReadTerms($_POST['chkReadTerms']))
{
$_SESSION['errors']['chkReadTerms'] = 'error';
$_SESSION['values']['chkReadTerms'] = '';
$errorsExist = 1;
}
//Wenn keine Fehler vorhanden, auf Erfolsmeldungsseite verweisen
if ($errorsExist == 0)
{
return 'allok.php';
}
else
{
//Wenn Fehler gefunden werden vorhanden Eingabe speichern
foreach ($_POST as $key => $value)
{
$_SESSION['values'][$key] = $_POST[$key];
}
return 'index.php';
}
}
private function validateUserName($value)
{
$value = $this->mMysqli->real_escape_string(trim($value));
if($value == null)
return 0;
$query = $this->mMysqli->query('SELECT user_name From users WHERE user_name="' .$value. '"');
if($this->mMysqli->affected_rows > 0)
return '0';
else
return '1';
}
private function validateName($value)
{
$value = trim($value);
if ($value)
return 1;
else
return 0;
}
private function validateGender($value)
{
return ($value == '0') ? 0 : 1;
}
private function validateBrithMonth($value)
{
return ($value == '' || $value > 12 || $value < 1) ? 0 : 1;
}
private function validateBirthDay($value)
{
return ($value == '' || $value > 31 || $value < 1) ? 0 : 1;
}
private function validateBirthYear($value)
{
$date= explode('#', $value);
if(!$date[0]) return 0;
if(!$date[1] || !is_numeric($date[1])) return 0;
if(!$date[2] || !is_numeric($date[2])) return 0;
return (checkdate($date[0], $date[1], $date[2])) ? 1 : 0;
}
private function validateEmail($value)
{
return (!eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$', $value)) ? 0 : 1;
}
private function validatePhone($value)
{
return (!eregi('^[0-9]{3}-*[0-9]{3}-*[0-9]{4}$',$value)) ? 0 : 1;
}
private function validateReadTerms($value)
{
return($value == 'true' || $value == 'on') ? 1 : 0;
}
}
?>
|