Page 1 of 1

Interference from CSS hacks - Headers already sent

Posted: Tue Apr 14, 2009 1:10 am
by anivad
I keep getting the 'headers already sent' error, and apparently this line is the culprit:

<!--[if !IE]>--> <link href="2_layout16.css" rel="stylesheet" type="text/css"> <!--<![endif]-->

I need that line there so that my site will display properly in different browsers; got the code off http://www.webdevout.net/css-hacks.

The relevant part of the code (line 5):

Code: Select all

<html>
<head>
<title>TEST PAGE</title>
<link rel=stylesheet href="layout17.css" type="text/css">
<!--[if !IE]>--> <link href="2_layout16.css" rel="stylesheet" type="text/css"> <!--<![endif]-->
</head>
 
<body bgcolor="black">
 
<div id="login">
 
<p>
<? include 'scheck.php' ?>
</p>
 
</div>
 
where scheck.php =

Code: Select all

 
<?PHP
 
session_start();
 
$scheck = (!(isset($_SESSION['login']) &&  $_SESSION['login'] != ''));
 
if ($scheck) {
print "<a href='loginpage.htm'>Login</a> | <a href='register.htm'>Register</a>";
}
else {
print "Logged in as user <b><a href='loginsuccess.htm'>" . $_SESSION['uname'] . "</a></b> | <a href='logout.php'>Logout</a>";
}
 
?>
 
How do I fix this?

Thanks!

Re: Interference from CSS hacks - Headers already sent

Posted: Tue Apr 14, 2009 7:02 am
by jaoudestudios
put your include at the top of the file

Re: Interference from CSS hacks - Headers already sent

Posted: Tue Apr 14, 2009 11:12 am
by anivad
Okay; guess I'll have to stick with that for now.

But what if I want the code to execute in the middle of the page, for example to display a certain lot of HTML code if a user is logged in, and a different lot if the user is not logged in? If I put the include at the top of the file, the HTML will also appear at the top of the file, where I don't want it to be.

In a related problem - how do I echo a default value, say 'Guest' from my MySQL database?

Thanks!

Re: Interference from CSS hacks - Headers already sent

Posted: Tue Apr 14, 2009 11:28 am
by Reviresco
Your session_start() must be at the top, before any other output (including HTML tags).

The other php stuff -- you can put elsewhere.

As for your second question -- don't know what you're asking, need more specifics.

Re: Interference from CSS hacks - Headers already sent

Posted: Thu Apr 16, 2009 9:03 am
by anivad
As for your second question -- don't know what you're asking, need more specifics.
For example if I have a page to greet visitors, and if they are logged in I want it to say:

"Welcome, $uname!" where $uname=$_SESSION['uname'] (or have the value grabbed from MySQL)

and 'Welcome, Guest!" if they are not logged in.

Is it possible to do this using just the 'Welcome, $uname!' code if I set the MySQL default value for 'uname' as 'Guest'?

Re: Interference from CSS hacks - Headers already sent

Posted: Fri Apr 17, 2009 12:22 pm
by Reviresco
Just use php:

Code: Select all

 
if ($uname == "") {
   $uname = 'Guest';
}