Hướng dẫn php display errors off

I just want to only turn on PHP errors and disable all notices and warnings in PHP files.

Nội dung chính

  • Warning Cakephp là gì?
  • Các bước thực hiện ẩn cảnh báo lỗi Cakephp như sau
  • Bước 1: Login Hosting trên trình duyệt
  • Bước 2: Xác định đường dẫn đến thư mục cần chỉnh sửa
  • Bước 3: Tìm và chỉnh sửa đoạn mã ẩn cảnh báo
  • Bước 4: kiểm tra lại

Nội dung chính

  • Warning Cakephp là gì?
  • Các bước thực hiện ẩn cảnh báo lỗi Cakephp như sau
  • Bước 1: Login Hosting trên trình duyệt
  • Bước 2: Xác định đường dẫn đến thư mục cần chỉnh sửa
  • Bước 3: Tìm và chỉnh sửa đoạn mã ẩn cảnh báo
  • Bước 4: kiểm tra lại

Hướng dẫn php display errors off

asked Dec 28, 2011 at 7:07

1

It is probably not the best thing to do. You need to at least check out your PHP error log for things going wrong ;)

# PHP error handling for development servers
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_flag log_errors on
php_flag ignore_repeated_errors off
php_flag ignore_repeated_source off
php_flag report_memleaks on
php_flag track_errors on
php_value docref_root 0
php_value docref_ext 0
php_value error_log /home/path/public_html/domain/PHP_errors.log
php_value error_reporting -1
php_value log_errors_max_len 0

answered Dec 28, 2011 at 7:14

impimp

1,0907 silver badges13 bronze badges

5

If you are in a shared hosting plan that doesn't have PHP installed as a module you will get a 500 server error when adding those flags to the .htaccess file.

But you can add the line

ini_set('display_errors','off');

on top of your .php file and it should work without any errors.

answered Sep 9, 2012 at 1:05

FortesFortes

91812 silver badges23 bronze badges

Try:

php_value error_reporting 2039

answered Dec 28, 2011 at 7:14

Sudhir BastakotiSudhir Bastakoti

97.8k15 gold badges156 silver badges161 bronze badges

5

Fortes is right, thank you.

When you have a shared hosting it is usual to obtain an 500 server error.

I have a website with Joomla and I added to the index.php:

ini_set('display_errors','off');

The error line showed in my website disappeared.

answered Apr 17, 2013 at 8:53

RichRich

691 silver badge1 bronze badge

Use:

ini_set('display_errors','off');

It is working fine in WordPress' config.php.

answered Dec 4, 2015 at 5:10

2

I used ini_set('display_errors','off'); and it worked great.

answered Apr 30, 2013 at 14:33

Warning Cakephp là gì?

Với các mã nguồn sử dụng Cakephp, điều thường gặp đó là các cảnh báo. Cảnh báo này nhằm mục đích cho lập trình viên biết lỗi ở đâu để khắc phục (debug). Tuy nhiên với các code cũ, thường ít ai fix triệt để các Warning này. Vì vậy Bạn cần ẩn nó đi để không ảnh hưởng đến giao diện website.

website lỗi nhìn sẽ như thế này!

Các bước thực hiện ẩn cảnh báo lỗi Cakephp như sau

Bạn cần có quyền truy cập Hosting / FTP / SSH để sửa nhé

ở hướng dẫn này, mính sẽ demo trên giao diện web Hosting DirectAdmin

Bước 1: Login Hosting trên trình duyệt

Điều này khỏi cần hướng dẫn nhé. các Bạn tự login vào Hosting

Với FTP và SSH các Bạn cũng login nha

Bước 2: Xác định đường dẫn đến thư mục cần chỉnh sửa

Thường thì config sẽ nằm trong đường dẫn này

app/Config/core.php

tất nhiên đây là đường dẫn trong thư mục public_html nhé. Hãy chọn cho đúng tên miền cần chỉnh sửa nếu Bạn có nhiều tên miền. Tránh nhầm lẫn nha

Một số lập trình viên chỉnh sửa thì Bạn tự tìm file tương ứng nhé

Bước 3: Tìm và chỉnh sửa đoạn mã ẩn cảnh báo

Như ảnh bước 2, các Bạn click vào nút “edit” của hàng core.php

Sau đó dùng tổ hợp phím crtl + F (tìm kiếm) và paste vào cụm từ này “Configure::write('debug'

Sau đó chỉnh sửa “2” thành “0”

Bước 4: kiểm tra lại

Hãy truy cập website xem đã hết lỗi chưa nhé

Nếu chưa, vui lòng chat với kỹ thuật tại HostingViet.vn

Chúng tôi luôn trực 24/24 để hỗ trợ Quý khách và các Bạn

Chúc các Bạn thành công!

Trung – Kỹ thuật viên HostingViet

I am trying to turn off all errors on my website. I have followed different tutorials on how to do this, but I keep getting read and open error messages. Is there something I am missing?

I have tried the following in my php.ini file:

;Error display
display_startup_errors = Off
display_errors = Off
html_errors = Off
docref_root = 0
docref_ext = 0

For some reason when I do a fileopen() call for a file which does not exist, I still get the error displayed. This is not safe for a live website, for obvious reasons.

Hướng dẫn php display errors off

asked Apr 11, 2013 at 12:52

3

I always use something like this in a configuration file:

// Toggle this to change the setting
define('DEBUG', true);

// You want all errors to be triggered
error_reporting(E_ALL);

if(DEBUG == true)
{
    // You're developing, so you want all errors to be shown
    display_errors(true);

    // Logging is usually overkill during development
    log_errors(false);
}
else
{
    // You don't want to display errors on a production environment
    display_errors(false);

    // You definitely want to log any occurring
    log_errors(true);
}

This allows easy toggling between debug settings. You can improve this further by checking on which server the code is running (development, test, acceptance, and production) and change your settings accordingly.

Note that no errors will be logged if error_reporting is set to 0, as cleverly remarked by Korri.

Hướng dẫn php display errors off

answered Apr 11, 2013 at 12:59

SherlockSherlock

7,4076 gold badges36 silver badges79 bronze badges

4

You should consider not displaying your error messages instead!

Set ini_set('display_errors', 'Off'); in your PHP code (or directly into your ini file if possible), and leave error_reporting on E_ALL or whatever kind of messages you would like to find in your logs.

This way you can handle errors later, while your users still don't see them.

Full example:

define('DEBUG', true);
error_reporting(E_ALL);

if (DEBUG)
{
    ini_set('display_errors', 'On');
}
else
{
    ini_set('display_errors', 'Off');
}

Or simply (same effect):

define('DEBUG', true);

error_reporting(E_ALL);
ini_set('display_errors', DEBUG ? 'On' : 'Off');

Hướng dẫn php display errors off

answered Feb 11, 2014 at 10:52

Hướng dẫn php display errors off

LeviteLevite

16.6k7 gold badges50 silver badges50 bronze badges

2

In php.ini, comment out:

error_reporting = E_ALL & ~E_NOTICE
error_reporting = E_ALL & ~E_NOTICE | E_STRICT
error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ER… _ERROR
error_reporting = E_ALL & ~E_NOTICE

By placing a ; ahead of it (i.e., like ;error_reporting = E_ALL & ~E_NOTICE)

For disabling in a single file, place error_reporting(0); after opening a php tag.

Hướng dẫn php display errors off

answered Apr 11, 2013 at 13:01

Vishnu RVishnu R

1,8493 gold badges25 silver badges45 bronze badges

1

In file php.ini you should try this for all errors:

error_reporting = off

Urs

4,8847 gold badges50 silver badges113 bronze badges

answered Apr 1, 2014 at 15:45

1

Let me quickly summarize this for reference:

  • error_reporting() adapts the currently active setting for the default error handler.

  • Editing the error reporting ini options also changes the defaults.

    • Here it's imperative to edit the correct php.ini version - it's typically /etc/php5/fpm/php.ini on modern servers, /etc/php5/mod_php/php.ini alternatively; while the CLI version has a distinct one.

    • Alternatively you can use depending on SAPI:

      • mod_php: .htaccess with php_flag options
      • FastCGI: commonly a local php.ini
      • And with PHP above 5.3 also a .user.ini
    • Restarting the webserver as usual.

If your code is unwieldy and somehow resets these options elsewhere at runtime, then an alternative and quick way is to define a custom error handler that just slurps all notices/warnings/errors up:

set_error_handler(function(){});

Again, this is not advisable, just an alternative.

answered Jul 30, 2014 at 1:16

mariomario

142k20 gold badges236 silver badges285 bronze badges

2

In file php.ini you should try this for all errors:

display_errors = On

Location file is:

  • Ubuntu 16.04:/etc/php/7.0/apache2
  • CentOS 7:/etc/php.ini

answered Mar 10, 2015 at 4:26

1

You can also use PHP's error_reporting();

// Disable it all for current call
error_reporting(0);

If you want to ignore errors from one function only, you can prepend a @ symbol.

@any_function(); // Errors are ignored

Hướng dẫn php display errors off

answered Apr 11, 2013 at 12:54

Tim S.Tim S.

13.3k7 gold badges43 silver badges71 bronze badges

1

I usually use PHP's built in error handlers that can handle every possible error outside of syntax and still render a nice 'Down for maintenance' page otherwise:

Format PHP error on production server

Hướng dẫn php display errors off

answered Mar 10, 2015 at 4:33

Hướng dẫn php display errors off

Vladimir RamikVladimir Ramik

1,9052 gold badges12 silver badges23 bronze badges

Open your php.ini file (If you are using Linux - sudo vim /etc/php5/apache2/php.ini)

Add this lines into that file

   error_reporting = E_ALL & ~E_WARNING 

(If you need to disabled any other errors -> error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE & ~E_WARNING)

    display_errors = On

And finally you need to restart your APACHE server.

answered Jan 5, 2016 at 9:26

Hướng dẫn php display errors off

UWU_SANDUNUWU_SANDUN

1,05713 silver badges18 bronze badges

It is not enough in case of PHP fpm. It was one more configuration file which can enable display_error. You should find www.conf. In my case it is in directory /etc/php/7.1/fpm/pool.d/

You should find php_flag[display_errors] = on and disable it, php_flag[display_errors] = off. This should solve the issue.

Hướng dẫn php display errors off

answered Jan 25, 2019 at 16:55

Vazgen ManukyanVazgen Manukyan

1,3701 gold badge11 silver badges17 bronze badges

It's been quite some time and iam sure OP's answer is cleared. If any new user still looking for answer and scrolled this far, then here it is.

Check your updated information in php.ini file

Using Windows explorer:

C/xampp/php/php.ini

Using XAMPP Control Panel

  1. Click the Config button for 'Apache' (Stop | Admin | Config | Logs)
  2. Select PHP (php.ini)

Can i create my own phpinfo()? Yes you can

  1. Create a phpinfo.php in your root directly or anywhere you want
  2. Place this
  3. Save the file.
  4. Open the file and you should see all the details.

How to set display_errors to Off in my own file without using php.ini

You can do this using ini_set() function. Read more about ini_set() here (https://www.php.net/manual/en/function.ini-set.php)

  1. Go to your header.php or index.php
  2. add this code ini_set('display_errors', FALSE);

To check the output without accessing php.ini file

$displayErrors = (ini_get('display_errors') == 1) ? 'On' : 'Off';
$PHPCore = array(
    'Display error' => $displayErrors
    // add other details for more output
);
foreach ($PHPCore as $key => $value) {
    echo "$key: $value";
}

answered Jul 30, 2020 at 23:50

Hướng dẫn php display errors off

DexterDexter

6,4723 gold badges35 silver badges34 bronze badges