Home > Backend Development > PHP Problem > How to output pop-up error message in php

How to output pop-up error message in php

小老鼠
Release: 2023-05-19 17:44:05
Original
1720 people have browsed it

How to output pop-up error prompts in php: 1. Open the corresponding PHP file; 2. Add "error_reporting(E_ALL);"; 3. Output through the "function cache_shutdown_error() {...}" method Just the error message.

How to output pop-up error message in php

The operating environment of this system: Windows 10 system, PHP version 7.1, DELL G3 computer.

php method of outputting error information

error_reporting(E_ALL);
function cache_shutdown_error() {
          $_error = error_get_last();
          if ($_error && in_array($_error['type'], array(1, 4, 16, 64, 256, 4096, E_ALL)))
{
                    header("Content-Type: text/html; charset=utf-8");
                    echo &#39;<font color=red>你的代码出错了:</font></br>&#39;;
                    echo &#39;致命错误:&#39; . $_error[&#39;message&#39;] . &#39;</br>&#39;;
                    echo &#39;文件:&#39; . $_error[&#39;file&#39;] . &#39;</br>&#39;;
                    echo &#39;在第&#39; . $_error[&#39;line&#39;] . &#39;行</br>&#39;;
                }
            }
 register_shutdown_function("cache_shutdown_error");
Copy after login

It is best to put it at the front. If the error is reported and terminated, this method cannot be executed.

In short, PHP output pop-up windows can be used to promptly prompt users with error messages, improve user experience, and enhance security. Hackers often exploit application vulnerabilities, so validation and error handling of input is crucial.

The above is the detailed content of How to output pop-up error message in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template