Trying to execute HTML after PHP code -


i making website can log in using http basic authentication. once person logs in correct credentials, start new session , have link continue page. on other page want check see if session has been started getting username session variable created on last page. if session variable exists, want execute pages html code. if session variable not exist, should give user link login page. know how can achieved?

// second page checking see if session variables exists code <?php session_start(); if (isset($_session['username'])) {     $username = $_session['username'];  // command execute rest of webpage after php closing tag } else {     die("<a href='index.php'>login</a>"); } ?>  <!-- html code needs executed --> <p>hi!</p> 

you try , wrap webpage content around if in php tags.

<?php     session_start();      if (isset($_session['username'])) {         $username = $_session['username'];         ?>             <p>hi!</p>         <?php     } else {         die("<a href='index.php'>login</a>");     } ?> 

edit

after consideration, die unneeded. can same if. return result, , execute additional php code in file if needed.

<?php     session_start();      if (isset($_session['username'])) {         $username = $_session['username'];         ?>             <p>hi!</p>         <?php     } else {         ?>             <a href='index.php'>login</a>         <?php     } ?> 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -