homepage Welcome to WebmasterWorld Guest from 54.166.255.168
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP and Cookies
headers already sent..but they aint!
knighty

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1100 posted 3:19 pm on Oct 22, 2002 (gmt 0)

everytime i use the right login/pass i get the error

Cannot add header information - headers already sent by (output started at C:\sites\php\login.php:1)

as far as I'm aware I have'nt set any headers

(the very first code on the page)

<?
if (($submit=='submit') && (($user!='') ¦¦ ($pass!='')))
{
require('user and password stuff.php');
$query="SELECT * FROM sometable WHERE username='$user' && password='$pass'";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
if ($num>0)
{
$user_id=mysql_result($result,$i,"user_id");
setcookie( "pfinduser", "$user", mktime(0, 0, 0, 5, 14, 2036) );
setcookie( "pfindpass", "$pass", mktime(0, 0, 0, 5, 14, 2036) );

$log = "yes";
}
else
{
$log = "no";
$log2 = "fail";
}
}
else
{
$log = "no";
}
if (isset($pfinduser))
{$log="yes";}
?>
<html>

 

dingman

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1100 posted 3:25 pm on Oct 22, 2002 (gmt 0)

<?php
ob_start();
...
?>

Ought to do it for you. I've had the same problem before, and although the docs seem to indicate that one ought to be able to send headers as long as you haven't produced any other output yet, it doesn't seem to be the case unless you explicitly turn on output buffering.

knighty

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1100 posted 3:29 pm on Oct 22, 2002 (gmt 0)

dingman,

ack! did'nt work - just get the same errors on the lines where the cookies get set

dingman

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1100 posted 3:35 pm on Oct 22, 2002 (gmt 0)

hmm... is output buffering turned off in your php.ini?

andreasfriedrich

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1100 posted 3:36 pm on Oct 22, 2002 (gmt 0)

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

[php.net...]

Did you check that there are no blank lines anywhere?

Telnet to your script and youŽll see what its output is up until you get that error message.

Andreas

lorax

WebmasterWorld Administrator lorax us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 1100 posted 3:38 pm on Oct 22, 2002 (gmt 0)

knighty,
[php.net...]

The comments should provide the answer but in a nutshell, make sure nothing (no blank lines or even a DTD) appear within the required file before the <?php .

dingman

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1100 posted 3:40 pm on Oct 22, 2002 (gmt 0)

I hope Andreas & Lorax are right, but I know I've had to turn on output buffering for files that have no requires, no includes, and failed to work when the first characters of the file were '<?php header('.

knighty

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1100 posted 3:45 pm on Oct 22, 2002 (gmt 0)

Thanks for the replies

I have fixed the problem, I had already cheacked for includes, blank lines etc a gazillion times.

I then copied all the text and pasted it into notepad and it works perfectly!

I no understandy, very bizarre I think somehow file was corrupted and inserting characters? thats the only thing I can think of anyway.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved