9 replies
Hey All

so a few things going on here I can use a hand with 1) I'm getting session error can't send header already sent issue and it's the very first thing being called I attached image for viewing as the 2) issue is looking at image when I add the session_start it messes up all the alignment of the page if I remove it works fine??

PHP Code:
<?php
session_start
();
if (!isset(
$_SESSION['username'])) {
echo 
"I'm truly Sorry However In Order To View This Section You Must Be Logged In.<a hfref='login.php'>Click Here To Login</a>";
exit();
}
include(
"connect.php");
?>
#sessionstart
  • Profile picture of the author Earnie Boyd
    Make sure the <?php is on line 1 column 1. You may need to look at the ob_start and ob_flush functions.
    Signature
    {{ DiscussionBoard.errors[6043746].message }}
  • Profile picture of the author solidsoul
    and why you think I'm loosing alignment of page?
    {{ DiscussionBoard.errors[6043906].message }}
  • Profile picture of the author solidsoul
    dunno OB's don't work I had already tried flush and start both changed nothing?
    {{ DiscussionBoard.errors[6043916].message }}
  • Profile picture of the author Earnie Boyd
    I'm thinking the alignment issue is do to the PHP error message being displayed. The session_start() function should not cause an alignment issue. Use a browser with some developer tools like Chrome or Firefox so that you can take a look at the elements individually on the page. Maybe some CSS file isn't loaded because of the PHP error?
    Signature
    {{ DiscussionBoard.errors[6043979].message }}
  • Profile picture of the author solidsoul
    ok, I believe the same as after I wrote that I had another look and yes it's prob cause the text it being output.. anyhow does anyone have another solution I can try to fix this error...
    {{ DiscussionBoard.errors[6044016].message }}
  • Profile picture of the author Earnie Boyd
    Can you zip the code file and post it for a look?
    Is this code included by some other file?
    Something has output to the browser before session_start() started, it doesn't have to be much a single space is all that is required for session_start() to produce the error.
    Signature
    {{ DiscussionBoard.errors[6044362].message }}
  • Profile picture of the author Stuart Macfarlane
    Unless I am mistaken you need to close the session at the end of your code... At the moment you are trying to open a session on top of a session thus the error headers already sent.
    {{ DiscussionBoard.errors[6047738].message }}
    • Profile picture of the author Earnie Boyd
      Originally Posted by Stuart Macfarlane View Post

      Unless I am mistaken you need to close the session at the end of your code... At the moment you are trying to open a session on top of a session thus the error headers already sent.
      No, that doesn't happen. A session_start() in one file begins the session, a session_start() in another continues the same session. See PHP: session_start - Manual for the example given for the function. The issue is that something has written output before session_start() is called. Maybe do something like

      <?php
      if (!isset($_SESSION)) {
      session_start();
      }
      ?>

      If you want to debug why the session already existed you could add the following to get clues about the session.

      <?php
      else {
      echo '<pre>' . print_r($_SESSION, TRUE) . '</pre>';
      }
      ?>
      Signature
      {{ DiscussionBoard.errors[6047962].message }}
      • Profile picture of the author Stuart Macfarlane
        Originally Posted by Earnie Boyd View Post

        No, that doesn't happen. A session_start() in one file begins the session, a session_start() in another continues the same session. See PHP: session_start - Manual for the example given for the function. The issue is that something has written output before session_start() is called. Maybe do something like

        <?php
        if (!isset()) {
        session_start();
        }
        ?>

        If you want to debug why the session already existed you could add the following to get clues about the session.

        <?php
        else {
        echo '<pre>' . print_r(, TRUE) . '</pre>';
        }
        ?>
        My bad well corrected Earnie
        {{ DiscussionBoard.errors[6048011].message }}

Trending Topics