0

I have a login script that created cookies when the user logs in. I also have the following if statement to change the buttons in the navigation bar if a user is signed in:

<?php
    if (isset($_SESSION['user_id'])) {
            echo "<li><a href='logout.php' class='btn btn-default navbar-btn'     role='button'>Log Out</a></li>";
            echo "<li><a href='myaccount.php' class='btn btn-default navbar-btn' role='button'>Dashboard</a></li>";
            echo "<li><a href='newlisting.php' class='btn btn-default navbar-btn' role='button'>Add New Listing</a></li>";
        } else {
            echo "<li><a href='login.php' class='btn btn-default navbar-btn' role='button'>Log In</a></li>";
            echo "<li><a href='signup.php' class='btn btn-default navbar-btn' role='button'>Sign Up</a></li>";
        }
        ?>

However, when I log in, I get the following error:

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/kizumit/public_html/header.php:54) in /home/kizumit/public_html/dbc.php on line 40

I'm able to log in and I stay logged in, but the buttons aren't changing. I'm wondering if there is a way for me to change the buttons based on a user being logged in, without interfering with the cookies that are being created when the user logs in. Any suggestions?

SyrupandSass
  • 335
  • 3
  • 5
  • 17
  • Your issue will lie on Line **40** of `/home/kizumit/public_html/dbc.php`. That's stopping you from starting your session (`session_start()`) which means your condition (`if (isset($_SESSION['user_id'])) {..`) **will** always return **false**. – Darren Jul 09 '14 at 06:26
  • 1
    this could shed some light, [link](http://stackoverflow.com/questions/8812754/cannot-send-session-cache-limiter-headers-already-sent) – user1978142 Jul 09 '14 at 06:27
  • Line 40 of dbc.php is the session_start() function, and that's in the function that checks to see if the user is logged in before showing the page. The only other session_start thing is in the login script itself. But when I take it out of the dbc.php file, it acts as if I'm not logged in at all and shows a blank spot where the rest of the page is supposed to load. – SyrupandSass Jul 09 '14 at 06:32
  • @SyrupandSass could you please include that code? There are characters being sent which is why the session isn't being instantiated properly – Darren Jul 09 '14 at 06:35
  • @kevinabelita Thank you so much!! I should have searched before asking. I just got extremely frustrated. – SyrupandSass Jul 09 '14 at 06:38
  • It is better to include the code or some link to pastebin for us to inspect the code. It seems something is echoed at the error line – Mostafa Talebi Jul 09 '14 at 06:44
  • yeah, most of the time thats the way to go, search first if youre issue has already a existing answer, saves time and effort since the answer is just laying in there. – user1978142 Jul 09 '14 at 06:48

0 Answers0