php显示错误消息和干净的内容

时间:2012-08-03 20:33:29

标签: php

我希望代码显示错误消息,同时删除页面内容

EG。

<?
echo 'welcome';
if (login==0)
{
    error("you can't access to this page");
}
content, content, content, content, content, content, content, content, content, content
ect.......
?>

输出

you can't access to this page

示例删除所有内容,但保留错误(“您无法访问此页面”);

2 个答案:

答案 0 :(得分:1)

在if语句中添加exit();。使用您的示例:

<?
echo 'welcome';
if (login==0)
{
    error("you can't access to this page");
    exit();
}
content, content, content, content, content, content, content, content, content, content
ect.......
?>

答案 1 :(得分:0)

您可以使用Matt提供的内容,这是另一种选择:

<?
echo 'welcome';
if(login==0) {
  error("you can't access to this page");
} else {
?>
content, content, content, content, content, content, content, content, content, content
<?php
}
?>