p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Beginning PHP (http://p2p.wrox.com/forumdisplay.php?f=95)

 squared_ring August 12th, 2004 05:12 AM

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; } ?>  Daniel Walker August 12th, 2004 10:12 AM 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  squared_ring August 13th, 2004 02:29 AM but dan, tat script is my whole file... and it doesnt have ne added html stuffs... ??? :(  Daniel Walker August 13th, 2004 04:22 AM 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

 squared_ring August 13th, 2004 05:51 AM

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

 Daniel Walker August 13th, 2004 06:06 AM

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

 squared_ring August 14th, 2004 05:29 AM

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

 All times are GMT -4. The time now is 01:34 PM.