Interference from CSS hacks - Headers already sent

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anivad
Forum Commoner
Posts: 80
Joined: Thu Apr 09, 2009 11:16 pm

Interference from CSS hacks - Headers already sent

Post 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!
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Interference from CSS hacks - Headers already sent

Post by jaoudestudios »

put your include at the top of the file
anivad
Forum Commoner
Posts: 80
Joined: Thu Apr 09, 2009 11:16 pm

Re: Interference from CSS hacks - Headers already sent

Post 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!
Reviresco
Forum Contributor
Posts: 172
Joined: Tue Feb 19, 2008 4:18 pm
Location: Milwaukee

Re: Interference from CSS hacks - Headers already sent

Post 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.
anivad
Forum Commoner
Posts: 80
Joined: Thu Apr 09, 2009 11:16 pm

Re: Interference from CSS hacks - Headers already sent

Post 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'?
Reviresco
Forum Contributor
Posts: 172
Joined: Tue Feb 19, 2008 4:18 pm
Location: Milwaukee

Re: Interference from CSS hacks - Headers already sent

Post by Reviresco »

Just use php:

Code: Select all

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