Question

If the users rank is not above 1, the exit function is used

The problem is, if the exit function is used, any code after it will not be displayed on the page

Let's pretend that my rank is not above 1, here is what happens:

<?php
if($memberinfo3['rank'] < 1)
{
echo "<br><br>Your accounts rank is not sufficient to access this page.";
exit;
}
echo "Passed!";
?>

<?php include 'template/sidebar.php'; ?> <---- NOT DISPLAYED

<?php include 'template/footer.php'; ?> <---- NOT DISPLAYED

I want to stop the exit function from not displaying the code on the rest of the page. I have looked up documentation on exit, die, and return, and have had no luck on fixing my problem

Was it helpful?

Solution

This is an architectural problem. The exit function is supposed to function like this. A better solution would be to do something like this:

<?php
    if($memberinfo3['rank'] < 1) {
        require 'guest.php';
    } else {
        require 'logged-in.php';
    }
?>

Try that instead.

Another option is to redirect them somewhere else. That can be a whole lot cleaner than showing an error message to the user as well.

<?php
    if($memberinfo3['rank'] < 1) {
        header('Location: /homepage_location.php');
    }
?>

But remember, if you use the header function you have to execute the statement prior to the output buffer being flushed (i.e., before echo, print, or other output statements).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top