Hi,

I use this code in Windows (wamp), it works fine. When i use it in Ubuntu it generates this error "Warning: Cannot modify header information - headers already sent by (output started at /var/www/toycar/header.php:9) in /var/www/toycar/classes/class.basket.php on line 17"

There is no blank space anywhere. What do i do?

Thanks

<?php
require_once("classes/class.session.php");
$sess=new SBase();
$values=$sess->getSession();
list($user, $loginlogout)=$values;
if($loginlogout=="Logout"){
echo "hi";
}else{
echo "no";
}
?>

there arent 17 lines in this file, so is the cause in the included session handler at around line 16

Line 9:

echo "no";

is the problem. You can't echo anything to the browser until after headers are sent.

Yes echo "no"; is the right one.

You can't echo anything to the browser until after headers are sent.

What shall i do in this case then?

<?php
require_once("classes/class.session.php");
$sess=new SBase();
$values=$sess->getSession();
list($user, $loginlogout)=$values;
if($loginlogout=="Logout"){ // assuming that this means you are logged in
$response = "1";
}else{ // assuming that this means you are not logged in
$response = "2";
}
?>
<html>
<head>
<title>My php page</title>
</head>
<body>
<?php
if ($response == "1') {
echo "You are able to see this page, aint that cool!";
} 
if ($response == "2') {
echo "You are not logged in.... <a href=\"login.php\">Login</a>";
}
?>
</body>
</html>

No it doesn't work. I realised that this problem starts as soon as after first HTML code. In this case error line is <?php after <body> tag.

No it doesn't work. I realised that this problem starts as soon as after first HTML code. In this case error line is <?php after <body> tag.

If this PHP after the body tag has anything in it that affects the headers, such as a header("Location: URLHERE"); call or anything of the sort, it'll throw an error. You can't do anything to the headers once you start outputting to the file. So any header-modifying code must be done before your <html> tag (or DTD tag, assuming, hopefully, that you are using one).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.