0

I want code to display error message, on same time remove page content

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.......
?>

Output

you can't access to this page

the exemple remove all content but it keep error("you can't access to this page");

1

2 Answers 2

1

Add exit(); inside your if statement. Using your example:

<?
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.......
?>
Sign up to request clarification or add additional context in comments.

3 Comments

Matt Harvey's answer is the simplest solution for this. You might also want to move echo "welcome" after the if(login == "0") condition check so that you do not see a welcome message and then a "you don't have access to this page" message
I want cleaning all output and keep only "you can't access to this page"
Yeah, just move echo 'welcome'; to after the } that closes the if statement. Otherwise, you'll need to use Javascript to clear the contents of the page before outputting the error. Also, you can change error("..."); to simply echo the error message.
0

You could use what Matt provides as well, here's another alternative:

<?
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
}
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.