PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 307,175 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,542 people online right now. Registration is fast and FREE... Join Now!




Can't get rid of: Headers already sent

 

Can't get rid of: Headers already sent, I want to refresh my webpage, but: Headers already sent

pjotrbee

18 Oct, 2007 - 04:08 AM
Post #1

New D.I.C Head
*

Joined: 18 Oct, 2007
Posts: 2


My Contributions
User can klik on menu-item [inloggen] in my startscript "tt.php".
Now "ttlogin.php" is called. It shows a webpage containing a login-form.
User can enter login-name.
The login-form calls itself (ttlogin.php) again and now login-verification is done.

After verification I want to show startscript "tt.php" again.
Because now $loginid is set, different menu-links will be shown and a different text in the content-part will be shown.

However ! I keep getting the message: Headers already sent.

How can I avoid this ??? crazy.gif mad.gif


There are no leading spaces before the "session_start()".
Incuded are: tt.php, ttlogin.php, ttmenu.php, tt.ccs



****** tt.php ******

CODE

<?php session_start() ?>
<?php
    $pagina_id="Startpagina";
?>

<html>
<head>
<title><?php echo $pagina_id; ?></title>
<link href="tt.css" rel="stylesheet" type="text/css">
</head>

<body>
<table>
<tr>
<?php
    if(isset($_SESSION["loginid"]))
{ ?>
    <td ><?php echo $_SESSION["loginid"] ?> </td>
<?php
} ?>
</tr>
</table>

<div class="menu">
<?php include("ttmenu.php");?>
</div>

<div class="content">
<?php if (!isset($_SESSION["loginid"])){ ?>
    <h2>Welkom op FinoFix webserver <?php include(".version")?></h2>
<?php } else { ?>
    <h2>U bent ingelogd op de FinoFix webserver.</h2>
<?php } ?>
</div>

</body>
</html>



**** ttlogin.php ****

CODE

<?session_start()?>
<?php $pagina_id="Inloggen"; ?>

<html>
<head>
<title><?php echo $pagina_id; ?></title>
<link href="tt.css" rel="stylesheet" type="text/css">
</head>

<body>

<!-- Als ingelogd, dan de loginnaam in de header tonen -->
<table>
<tr>
<?php
    if(isset($_SESSION["loginid"]))
{ ?>
    <td ><?php echo $_SESSION["loginid"] ?> </td>
<?php
} ?>
</tr>
</table>

<div class="menu">
<?php include("ttmenu.php");?>
</div>

<div class="content">
<?php
if (!empty($_POST)){
    //
    //  STAP 2  Inlognaam checken en daarna nieuwe menuopties tonen
    //
    $loginid=$_POST["loginid"];

    // Hier wachtwoordcontrole doen ...

    $_SESSION['loginid']=$loginid;

    header("Location:tt.php");

} else {
    //
    //  STAP 1  Inlog-variabelen nog niet gezet: dus inloggen via inlog-scherm
    //
?>

    <h2>Inloggen</h2>
    <hr>
    <form name="form1" method="post" action="<?php echo($_SERVER["PHP_SELF"]);?>">
    <br>Gebruikersnaam (demo)<br>
    <input name="loginid" type="text"><br><br>
      <input type="submit" name="Submit" value="Inloggen">
    </form>

<?php
}
?>

</div>
</body>
</html>



**** ttmenu.php ****


CODE

<div id="list-menu">
<ul>
    <li>
    <a href="tt.php">Welkom</a><br> </li>    

    <?php
    if (!isset($_SESSION["loginid"]))
    { ?>
        <li><a href="ttlogin.php">Inloggen</a><br>
    <?php
    } else { ?>
        <li><br><a class="n" href="ttlogin.php">Opnieuw inloggen</a></li>
    <?php
    } ?>
</ul>
</div>



**** tt.css ****

CODE

.header {
    position: absolute;
    left: 10px;
    width: 94%;
    padding: 0px;
    height: 80px;
    background:#FF9900;
    font-family:arial;
}
.header td {
    font-family:arial;
    font-size: 12;
}

.menu {
    position: absolute;
    left: 10px;
    top: 82px;
    height: 82%;
    width: 150px;
    background:#FF9900;
    font-family:arial;
    font-size:12;
}

body {
    font-family:arial;
    color: black;
    background-color: #FFCC33;
    font-size:12;
}

.content {
    position: absolute;
    top: 82px;
    margin-left: 150px;
    width: 100%;
    height: 70%;
    padding-top: 3em;
    padding-left: 2em;
}
.footer{
    position:absolute;
    left:10px;
    width:94%;
    padding: 0px;
    bottom:20;
    background:#FF9900;
    font-family:arial;
    font-size:0.8em;
}

table {
    font-family:arial;
    font-size:12;
}

/* in test.htm: <div id=list-menu> ..ul.. </div> */
#list-menu ul {
    margin: 10;
    padding: 0;
    list-style-type: none;
    font-family: arial, arial, sanf-serif;
    font-size: 12;
}

#list-menu li {
    margin: 10px 0 0;
}

#list-menu a {
    color: #fff;
    background: #fff;
    display: block;
    width:120px;
    padding: 2px 2px 2px 10px;
    border: 1px solid #000000;
    text-decoration: none; /*lets remove the link underlines*/
}

#list-menu a:link, #list-menu a:active, #list-menu a:visited {
    color: #000000;
}
#list-menu a:hover {
    border: 1px solid #000000;
    background: #333333;
    color: #ffffff;
}

#rechts a
{ color: $blue;}

h1 {
  font-family: Helvetica, Geneva, Arial,
        SunSans-Regular, sans-serif }
h2 {
  font-family: Helvetica, Geneva, Arial,
        SunSans-Regular, sans-serif }

a:link {
  color: blue }
  
a:visited {
  color: purple
}
  
address {
  margin-top: 1em;
  padding-top: 1em;
  border-top: thin dotted;
  font-size: 12px;
}


User is offlineProfile CardPM
+Quote Post

 
Reply to this topicStart new topic
Replies(1 - 5)

fxitsolutions

RE: Can't Get Rid Of: Headers Already Sent

18 Oct, 2007 - 04:18 AM
Post #2

New D.I.C Head
*

Joined: 1 Oct, 2007
Posts: 31


My Contributions
Try moving the form processing code above the HTML tag and use variables to error support it.
User is offlineProfile CardPM
+Quote Post

nav33n

RE: Can't Get Rid Of: Headers Already Sent

18 Oct, 2007 - 04:47 AM
Post #3

D.I.C Head
**

Joined: 2 Oct, 2007
Posts: 71



Thanked: 6 times
My Contributions
You shouldn't output anything before calling header function. Using html tags, space or any print statement before header will generate this error. You can avoid this by either not outputting anything before header function OR by using output buffer . Use ob_start(); ( http://in2.php.net/ob_start )
as the 1st line of your code and the last line of your code should be
ob_end_flush();
( http://in2.php.net/ob_end_flush )

Hope this helps smile.gif
User is offlineProfile CardPM
+Quote Post

pjotrbee

RE: Can't Get Rid Of: Headers Already Sent

18 Oct, 2007 - 05:36 AM
Post #4

New D.I.C Head
*

Joined: 18 Oct, 2007
Posts: 2


My Contributions
QUOTE(fxitsolutions @ 18 Oct, 2007 - 05:18 AM) *

Try moving the form processing code above the HTML tag and use variables to error support it.



Hoi, icon_up.gif

De opmerking had ik al vaak zat gelezen, maar na jouw antwoord viel het kwartje pas echt. En het werkt !!
Bedankt.
User is offlineProfile CardPM
+Quote Post

1lacca

RE: Can't Get Rid Of: Headers Already Sent

18 Oct, 2007 - 05:45 AM
Post #5

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 33 times
My Contributions
QUOTE(pjotrbee @ 18 Oct, 2007 - 03:36 PM) *

Hoi, icon_up.gif

De opmerking had ik al vaak zat gelezen, maar na jouw antwoord viel het kwartje pas echt. En het werkt !!
Bedankt.

Please use English as this is the official language of the forum, and most users probably didn't understand a word of your answer!
Anyway, as I look at it, my guess is that it has worked for you, and you've thanked him for his answer.
User is offlineProfile CardPM
+Quote Post

fxitsolutions

RE: Can't Get Rid Of: Headers Already Sent

18 Oct, 2007 - 07:47 AM
Post #6

New D.I.C Head
*

Joined: 1 Oct, 2007
Posts: 31


My Contributions
no problem buddy icon_up.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 07:15PM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month