 |
| 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
|
|
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
cannot set cookie
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
|
|
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
|
|
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
|
|
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 likes of which a webserver wraps around an excel spreadsheet, text file, or any other content, in order to send it across the web. In deed, it is these headers, not the HTML headers that the PHP header directive modifies. Web servers will attempt to automatically wrap appropriate headers around any content they are asked to send. If there is white space before the opening <?php tag in your PHP file, the server will wrap a MIME header around it. Indeed, even if the script was working, the moment you made a call to header('loaction...' the server would have to generate a header on the fly, for you, to hold your header modification.
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
|
|
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
|
|
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
|
|
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.....
|
|
 |