Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To display an entire page using an else statement in PHP, you can use a combination of HTML and PHP code. Here's an example:

<?php
    $loggedin = true; // Example variable

    if ($loggedin) {
        echo "Welcome, you're logged in!";
    } else {
        ?>
        <!DOCTYPE html>
        <html>
            <head>
                <title>My Page Title</title>
            </head>
            <body>
                <h1>Welcome to my website</h1>
                <p>Please log in to access this page</p>
            </body>
        </html>
        <?php
    }
?>

In this example, if the $loggedin variable is true, the code will display a simple message. If the $loggedin variable is false, the code will display an entire HTML page with a heading and a paragraph of text. The <?php and ?> tags allow you to switch between PHP and HTML code within the same document.