GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 03-Apr-2009, 10:23
sameer795 sameer795 is offline
New Member
 
Join Date: Apr 2009
Posts: 3
sameer795 is on a distinguished road

Error about headers being not set


hi,

setting up cookies is giving me an error about headers being not set.

all the trailing spaces i have removed in my small code.


let me know if there is any configuration left to do.
Attached Files
File Type: doc cookie.doc (25.5 KB, 5 views)
  #2  
Old 03-Apr-2009, 16:55
MisterChucker's Avatar
MisterChucker MisterChucker is offline
Junior Member
 
Join Date: Mar 2009
Location: Cyberspace, Earth
Posts: 53
MisterChucker is a jewel in the roughMisterChucker is a jewel in the roughMisterChucker is a jewel in the rough

Re: beginner error


See this thread: http://www.gidforums.com/t-18032.html (skip to post #4)
  #3  
Old 04-Apr-2009, 05:52
sameer795 sameer795 is offline
New Member
 
Join Date: Apr 2009
Posts: 3
sameer795 is on a distinguished road

Re: Error about headers being not set


thanks for your kind reply.
but this is not helping me.. if you check out the file ive attached, you'll see that i have fulfilled the requirements regarding the spaces and prioritiesm but the error still persists.

Here is the error:

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\login.php:5) in C:\wamp\www\login.php on line 6


The same code works on different machines.
  #4  
Old 04-Apr-2009, 11:15
MisterChucker's Avatar
MisterChucker MisterChucker is offline
Junior Member
 
Join Date: Mar 2009
Location: Cyberspace, Earth
Posts: 53
MisterChucker is a jewel in the roughMisterChucker is a jewel in the roughMisterChucker is a jewel in the rough

Re: Error about headers being not set


Did you read the fourth post in that thread?

Anyway, your code is
PHP Code:

<head>
<title>Processing...</title>
</head>
<body>
<?php
setcookie('test',45,time()+(60*60));
?>
</body>
</html> 

That is the same as
PHP Code:

<?php
echo "<head>\n<title>Processing...</title>\n</head>\n<body>\n";
setcookie('test',45,time()+(60*60));
echo "</body>\n</html>";
?>

The problem is that when you use echo or straight HTML, you are implicitly sending the headers, which you can't do before the setcookie() function.

Use this code:
PHP Code:

<?php setcookie('test', 45, time() + 3600); ?>
<html>
<head>
<title>Cookie Processed</title>
</head>
<body>

</body>
</html>
or this code
PHP Code:

<?php ob_start(); ?>
<html>
<head>
<title>Cookie Processed</title>
</head>
<body>
<?php setcookie('test', '45', time() + 3600); ?>
</body>
</html>
<?php ob_end_flush(); ?>

Last edited by MisterChucker : 04-Apr-2009 at 11:19. Reason: Oops, forgot time()
  #5  
Old 07-Apr-2009, 03:02
sameer795 sameer795 is offline
New Member
 
Join Date: Apr 2009
Posts: 3
sameer795 is on a distinguished road

Re: Error about headers being not set


Thankyou.. This works!!

I took lessons from Lynda's training videos. My script matched the guy's script. At first attempt my script worked fine. but due to system failure, i had to format my pc only to find that this script isn't working anymore.

I did read the 4th post in the thread, but due to what i learned, i was unable to find the difference.

Anyways,
Thanks for your kind help.
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Two-Tier data dissemination code installation problem nidhibansal1984 Computer Software Forum - Linux 6 16-Sep-2007 11:13
Linked Lists advice request promsan C Programming Language 74 23-May-2007 09:29
Major newbie problem cynack MS Visual C++ / MFC Forum 1 08-Apr-2007 12:25
Winsock error when compiling FLTK 2.0 Projects mauriciorossi FLTK Forum 3 16-Aug-2005 11:18
Help with syntax errors PeteGallo C Programming Language 7 08-Aug-2005 21:30

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:11.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.