如何在PHP中将错误显示为警告框

时间:2015-02-18 10:28:15

标签: php


我想将错误显示为窗口浏览器警报 喜欢 - Click Here
但我想使用URL as - Click Here
有没有办法使用?
我的代码如下:

<?php
if(isset($_GET['i'])){
echo '<script type="text/javascript">alert("INFO:  ' . $_GET['i'] . '");</script>';
}
?>

1 个答案:

答案 0 :(得分:1)

根据您的错误代码显示消息:

<?php
    if(isset($_GET['i'])){
        switch($_GET['i']) {
            case 100:
                $errorMsg = "Please use a valid email"; // For example
            break;
            case 200:
                $errorMsg = "Email already in use";
            break;
            default:
                // If $_GET['i'] has an unexpected value
                $errorMsg = "Oops, there was an unknown error";
            break;
        }
        echo '<script type="text/javascript">alert("INFO:  '.$errorMsg.'");</script>';
    }
?>