Wrox Programmer Forums PHP ( Cannot modify header information)
 |
 Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
 Welcome to the p2p.wrox.com Forums. You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com

August 12th, 2004, 05:12 AM
 squared_ring Registered User Join Date: Aug 2004 Posts: 4 Thanks: 0 Thanked 0 Times in 0 Posts
PHP ( Cannot modify header information)

hello ppl.. well i was learing to use cookies, but i am stuck cus the below posted script generates

Warning: Cannot modify header information - headers already sent by (output started at D:\xtams\xtams-php\pm.php:1) in D:\xtams\xtams-php\pm.php on line 15

error occors at the red indicated lines..

I tried to check if this script is sending ne info or white space to the browser.. but doesnt seem to be.. i mean before setcookie() funcn.

pls help..
thanks

<?php
$dbhost = 'localhost';$dbusername = '';
$dbpasswd = '';$database_name = 'xpm_db';
$conn = mysql_pconnect("$dbhost","$dbusername","$dbpasswd" ) or die ("Couldn't connect to server.");
$db = mysql_select_db("$database_name", $conn) or die("Couldn't select database.");$username=$_REQUEST["form_username"];$password=$_REQUEST["form_password"];$sql = "SELECT * FROM users WHERE user='" . $username. "' AND pass='".$password."'";
$result = mysql_query($sql,$conn) or die(mysql_error());$RecTotal= mysql_num_rows($result); if ($RecTotal != 0)
{
setcookie("xpm_user", $row["user"], time()+60, "/", ".localhost.", 0) or die("cannot set cookie"); } else { Header ("location: \"login.php\""); exit; } ?> August 12th, 2004, 10:12 AM  Daniel Walker Friend of Wrox Join Date: Jun 2003 Posts: 256 Thanks: 0 Thanked 0 Times in 0 Posts Check for white space outside of your <?php ?> tags. White space counts as content, so the webserver will wrap a header around it automatically. Then when you try to modify the headers, the PHP engine correctly reports that the headers have benn and gone and been sent, and so lie beyond the realms of modifyability. Take it easy, Dan August 13th, 2004, 02:29 AM  squared_ring Registered User Join Date: Aug 2004 Posts: 4 Thanks: 0 Thanked 0 Times in 0 Posts but dan, tat script is my whole file... and it doesnt have ne added html stuffs... ??? :( August 13th, 2004, 04:22 AM  Daniel Walker Friend of Wrox Join Date: Jun 2003 Posts: 256 Thanks: 0 Thanked 0 Times in 0 Posts Yes, but I'm not talking and about a HTML <head /> header: I mean a hypertext MIME header - stuff like: Expires: Mon, 26 Jul 1997 05:00:00 GMT" Last-Modified: Monday,11th May 2003 19:06:13 GMT" Cache-Control: no-cache, must-revalidate" Pragma: no-cache Content-type: application/x-msexcel Content-Disposition: attachment; filename=$file
Content-Description: PHP Generated Data

The error is saying that something has caused the server to generate a header for you already, so you cannot modify it. The most likely cause is whitespace.

Take it easy,
Dan

August 13th, 2004, 05:51 AM
 squared_ring Registered User Join Date: Aug 2004 Posts: 4 Thanks: 0 Thanked 0 Times in 0 Posts

hi again.. well i get exactly what u mean... but the thing is how am i to go bout hunting for that header created ("that irritating white space")....

August 13th, 2004, 06:06 AM
 Daniel Walker Friend of Wrox Join Date: Jun 2003 Posts: 256 Thanks: 0 Thanked 0 Times in 0 Posts

Well, check if there is a newline, space characters, or anythin else before that opening <?php. In other words, the "<" of "<?php" should be on line one, character one of your file.

Whenever you get this error message, this is the first thing to check.

Of course, if it's not that, then I've led you astray, so let me know, and I'll have another go... :)

August 14th, 2004, 05:29 AM
 squared_ring Registered User Join Date: Aug 2004 Posts: 4 Thanks: 0 Thanked 0 Times in 0 Posts

ATLAST.... got tat white space... :D well thanks a lot dan.. if nething i get back to u if u don mind.. neway thanks once again.....

 Similar Threads Thread Thread Starter Forum Replies Last Post How to modify flash so it pulls php url every 15 s method Flash (all versions) 4 February 27th, 2007 06:19 PM Yet another Cannot modify header question TimB Beginning PHP 2 November 26th, 2005 11:43 PM Modify header and footer of word file in ASP Andraw Classic ASP Basics 1 January 14th, 2005 08:04 PM [Question]Warning: Cannot modify header informatio unknownu Beginning PHP 1 August 19th, 2004 05:16 AM Cannot add header information.... cmiller Beginning PHP 1 September 2nd, 2003 07:02 PM