0

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";
}
?>
5
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by EvolutionFallen
0

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

0

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?

0
<?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>
0

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.

0

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).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.