Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 12th, 2004, 05:12 AM
Registered User
 
Join Date: Aug 2004
Location: , , Singapore.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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;
    }
?>

Reply With Quote
  #2 (permalink)  
Old August 12th, 2004, 10:12 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #3 (permalink)  
Old August 13th, 2004, 02:29 AM
Registered User
 
Join Date: Aug 2004
Location: , , Singapore.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

but dan, tat script is my whole file... and it doesnt have ne added html stuffs... ??? :(

Reply With Quote
  #4 (permalink)  
Old August 13th, 2004, 04:22 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #5 (permalink)  
Old August 13th, 2004, 05:51 AM
Registered User
 
Join Date: Aug 2004
Location: , , Singapore.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #6 (permalink)  
Old August 13th, 2004, 06:06 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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... :)
Reply With Quote
  #7 (permalink)  
Old August 14th, 2004, 05:29 AM
Registered User
 
Join Date: Aug 2004
Location: , , Singapore.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:49 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.