Wyświetlanie wszystkich błędów i ostrzeżeń [duplikat]
Aktualizacja 2:
Usunąłem teraz następujące z .plik php:
<?php error_reporting( E_ALL ); ?>
Ustawiłem display_erros w php.ini jak następuje:
Display_errors = On
Raportowanie błędów jest ustawione na następujące w php.ini
:
Error_reporting = E_ALL / E_STRICT
Po ponownym uruchomieniu Apache, nadal nie dostaję żadnych błędów/ostrzeżeń.
Aktualizacja 1:
Zmieniłem error_reporting w php.ini
z:
Error_reporting = E_ALL & ~E_DEPRECATED
Do
Error_reporting = E_ALL / E_STRICT
Po czym zrestartowałem Apache, np.
/etc / init.d / apache2 restart
Ale strona nadal nie wyświetla żadnych błędów/ostrzeżeń.
ORYGINALNE PYTANIE:
Poniższy skrypt generuje Ostrzeżenie, ponieważ $err jest wewnątrz instrukcji if. Dlaczego to Ostrzeżenie nie jest wyświetlane na stronie PHP w przeglądarce internetowej?
[12]} muszę spojrzeć na dzienniki Apache, aby zobaczyć Ostrzeżenie. Ponadto, jeśli celowo zmienię "insert into" na "delete into", nie wyświetli błędu na stronie PHP. Dlaczego błędy nie są wyświetlane na rzeczywistej stronie PHP?<?php
error_reporting(E_ALL);
?>
<html>
<head>
<title></title>
<link rel="icon" type="image/png" href="favicon.ico">
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$err = array();
if (empty( $_POST['display_name']))
$err[] = "display name field is required";
if (empty( $_POST['email']))
$err[] = "email field is required";
if (empty( $_POST['password']))
$err[] = "password field is required";
if (!$err) {
try {
$DBH = new PDO("mysql:host=localhost;dbname=database1", "user", "pass");
$DBH->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$STH = $DBH->prepare("delete into table1 (display_name, email, password) values ( :display_name, :email, :password )");
$STH->bindParam(':display_name', $_POST['display_name'], PDO::PARAM_STR, 100);
$STH->bindParam(':email', $_POST['email'], PDO::PARAM_STR, 100);
$STH->bindParam(':password', $_POST['password'], PDO::PARAM_STR, 100);
$STH->execute();
$STH = $DBH->prepare("delete into table2 ( username, status, users_id ) values ( :username, :status, :users_id )");
$strStatus = 1;
$STH->bindParam(':username', $_POST['display_name'], PDO::PARAM_STR, 100);
$STH->bindParam(':status', $strStatus, PDO::PARAM_INT, 1);
$STH->bindParam(':users_id', $_POST['referer'], PDO::PARAM_INT, 1);
$STH->execute();
$DBH = null;
}
catch (PDOException $e) {
echo $e->getMessage();
}
header("Location: " . $_SERVER['PHP_SELF']);
exit;
}
else {
foreach ($_POST as $key => $val) {
$form[$key] = htmlspecialchars($val);
}
}
}
else {
$form['display_name'] = $form['email'] = $form['password'] = '';
}
?>
</head>
<body>
<?php foreach($err as $line) { ?>
<div style="error"><?php echo $line; ?></div>
<?php } ?>
<h1>Register</h1>
<form method="post">
Referers id:<br/>
<input type="text" name="referer" /><br/><br/>
Name:<br/>
<input type="text" name="display_name" value="<?php echo $form['display_name']; ?>" /><br/><br/>
Email:<br/>
<input type="text" name="email" value="<?php echo $form['email']; ?>" /><br/><br/>
Password:<br/>
<input type="text" name="password" value="<?php echo $form['password']; ?>" /><br/><br/>
<input type="submit" value="register" />
</form>
</body>
</html>
6 answers
Błędy wyświetlania mogą być wyłączone w pliku php.ini
lub pliku konfiguracyjnym Apache.
Możesz go włączyć w skrypcie:
error_reporting(E_ALL);
ini_set('display_errors', '1');
Powinieneś zobaczyć te same komunikaty w dzienniku błędów PHP.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-09-25 21:11:08
Udało mi się uzyskać wszystkie błędy za pomocą poniższego kodu:
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2019-07-31 20:10:22
Prosto z php.plik ini:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Error handling and logging ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This directive informs PHP of which errors, warnings and notices you would like
; it to take action for. The recommended way of setting values for this
; directive is through the use of the error level constants and bitwise
; operators. The error level constants are below here for convenience as well as
; some common settings and their meanings.
; By default, PHP is set to take action on all errors, notices and warnings EXCEPT
; those related to E_NOTICE and E_STRICT, which together cover best practices and
; recommended coding standards in PHP. For performance reasons, this is the
; recommend error reporting setting. Your production server shouldn't be wasting
; resources complaining about best practices and coding standards. That's what
; development servers and development settings are for.
; Note: The php.ini-development file has this setting as E_ALL. This
; means it pretty much reports everything which is exactly what you want during
; development and early testing.
;
; Error Level Constants:
; E_ALL - All errors and warnings (includes E_STRICT as of PHP 5.4.0)
; E_ERROR - fatal run-time errors
; E_RECOVERABLE_ERROR - almost fatal run-time errors
; E_WARNING - run-time warnings (non-fatal errors)
; E_PARSE - compile-time parse errors
; E_NOTICE - run-time notices (these are warnings which often result
; from a bug in your code, but it's possible that it was
; intentional (e.g., using an uninitialized variable and
; relying on the fact it is automatically initialized to an
; empty string)
; E_STRICT - run-time notices, enable to have PHP suggest changes
; to your code which will ensure the best interoperability
; and forward compatibility of your code
; E_CORE_ERROR - fatal errors that occur during PHP's initial startup
; E_CORE_WARNING - warnings (non-fatal errors) that occur during PHP's
; initial startup
; E_COMPILE_ERROR - fatal compile-time errors
; E_COMPILE_WARNING - compile-time warnings (non-fatal errors)
; E_USER_ERROR - user-generated error message
; E_USER_WARNING - user-generated warning message
; E_USER_NOTICE - user-generated notice message
; E_DEPRECATED - warn about code that will not work in future versions
; of PHP
; E_USER_DEPRECATED - user-generated deprecation warnings
;
; Common Values:
; E_ALL (Show all errors, warnings and notices including coding standards.)
; E_ALL & ~E_NOTICE (Show all errors, except for notices)
; E_ALL & ~E_NOTICE & ~E_STRICT (Show all errors, except for notices and coding standards warnings.)
; E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR (Show only errors)
; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
; Development Value: E_ALL
; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
; http://php.net/error-reporting
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
Dla czystego rozwoju wybieram:
error_reporting = E_ALL ^ E_NOTICE ^ E_WARNING
Również nie zapomnij umieścić display_errors na
display_errors = On
Następnie uruchom ponownie serwer Apache na Ubuntu:
sudo /etc/init.d/apache2 restart
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2019-07-31 20:07:17
Błędy PHP mogą być wyświetlane za pomocą jednej z poniższych metod:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
Więcej Szczegółów:
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2019-07-31 20:11:35
Ustaw je na php.ini
:
;display_startup_errors = On
display_startup_errors=off
display_errors =on
html_errors= on
Ze strony PHP użyj odpowiedniego filtra do raportowania błędów.
error_reporting(E_ALL);
Filery mogą być wykonane zgodnie z wymaganiami.
E_ALL
E_ALL | E_STRICT
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2019-07-31 20:08:05
Możesz zobaczyć szczegółowy opis tutaj .
ini_set('display_errors', 1);
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);
// Report all PHP errors (see changelog)
error_reporting(E_ALL);
// Report all PHP errors
error_reporting(-1);
// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
Changelog
5.4.0 E_STRICT stał się częścią E_ALL
5.3.0 wprowadzono e_deprecated i E_USER_DEPRECATED.
5.2.0 wprowadzono e_recoverable_error.
Wprowadzono 5.0.0 E_STRICT (nie jest częścią E_ALL).
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2019-07-31 20:12:34