reggie jones
reggie jones

Reputation: 99

having php indent properly on echo?

I recently created a new login-register system for myself but i'm having issues with htmls indenting when echoed from php, Now that i've really looked at it, i realized that echoing a entire page isnt the smartest idea, unless it is?

<?php

if (isset($_SESSION['sessionId'])) {
    echo('This is the new content after login.');
} else{
    echo 'This is the login page';
}

?>

above is my index.php the first echo would echo the entire page of content the user would see after they logged in.

Second is the login form.

what would be the easiest way to go about this?

Upvotes: 0

Views: 213

Answers (2)

Omer Hijazi
Omer Hijazi

Reputation: 97

You can try echoing your HTML output like so

<?php

    if (isset($_SESSION['sessionId'])) {
    echo '<br><p>';
    echo'This is the new content after login.';
    echo '</p>';
    } else{
    echo '<br><p>';
    echo '  This is the login page';
    echo '</p>';
    }

    ?>

You'll see the above code in view source if you use it Output:

<br>
<p>
&nbsp&nbspThis is the content after login
</p>
second output
<br>
<p>
&nbsp&nbspThis is the login page
</p>


P.S. BTW why are you using brackets for one echo and none for the other ???

Upvotes: 1

qBen_Plays
qBen_Plays

Reputation: 258

You can do something like this

<?php

if (isset($_SESSION['sessionId'])) {
    readfile("/path/to/html/file/new_content.html");
} else{
    readfile("/path/to/html/file/login.html");
}

?>

Upvotes: 1

Related Questions