1

When I type in the direct URL to access the page that holds the database connection, db_connect.php on the website, it brings back a message of being successful. When I require it once on my master header page to determine what to show the website visitor (ie. if they're logged in it will show a set of links. If not, it will show a different set) it suddenly decides to error out and kills the rest of the PHP on the page. When I get rid of the require_once that links to the DB connection, all the PHP works fine. I've even tried using a relative URL. I am going to try one last thing but just wanted to get input on this. My guess is that I can't store the database connection in a folder.

<?php
    require_once("account-management/db_connect.php");
    session_start();
    
        if (isset($_SESSION['user_lister_id']) && ($_SESSION['email'])) {
            echo '<section class="topnavbar">';
            echo '<div id="top-login">';
            echo '<a href="#">Listing Profile</a> / <a href="#">Account Settings</a> / <a href="#">Case Requests</a>';
            echo '</div>';
            echo '</section>';
        } else {
            echo '<section class="topnavbar">';
            echo '<div id="top-register">';
            echo '<a href="#">Client Register</a> / <a href="#">Lister Register</a>';
            echo '</div>';
            echo '<div id="top-login">';
            echo '<a href="#">Client Login</a> / <a href="#">Lister Login</a>';
            echo '</div>';
            echo '</section>';
        }
?>
            <section class="header-grid">
        <img src="../images/Logo.png" width="120" />
        <div id="ad-field">This content coming soon!</div>
</section>
  • **Move** `session_start();` to the top of the page please – Ken Lee Mar 08 '22 at 01:18
  • Is `account-management` in the same directory as your webpage? If it is higher in the folder hierarchy, you need to specify it in the path : `../account-management/db_connect.php`, etc. – maqc Mar 08 '22 at 01:25
  • Moving the session_start(); worked. Thank you to both of you for your suggestions. –  Mar 08 '22 at 04:49

0 Answers0