Current location: Hot Scripts Forums » Programming Languages » PHP » cannot modify header


cannot modify header

Reply
  #1 (permalink)  
Old 06-01-05, 05:05 PM
kalinchuk kalinchuk is offline
Wannabe Coder
 
Join Date: Jun 2004
Location: ...
Posts: 110
Thanks: 0
Thanked 0 Times in 0 Posts
cannot modify header

i get this error:
Warning: Cannot modify header information - headers already sent by (output started at C:\test\top.php:5) in C:\test\main.php on line 7

what can be the problem, im just redirecting with the header function...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 06-01-05, 05:21 PM
Jaffizzle Jaffizzle is offline
Newbie Coder
 
Join Date: May 2005
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
check for white spaces before the <?php and after the ?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 06-01-05, 05:29 PM
kalinchuk kalinchuk is offline
Wannabe Coder
 
Join Date: Jun 2004
Location: ...
Posts: 110
Thanks: 0
Thanked 0 Times in 0 Posts
it still doesnt work...
here ismy code:
PHP Code:

<?php

$test 
"1";
echo 
"some text here...";
if(
$test == '1')
{
header("location: test2.php");
}
echo 
"...";
?>
and i get that error
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 06-01-05, 05:41 PM
Jaffizzle Jaffizzle is offline
Newbie Coder
 
Join Date: May 2005
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Hmm...the code looks fine to me.

I also tested it and it works perfectly on my end.

----edits-----
decided to do a lil bit of googling

try this ini_set("output_buffering","1");
or check that its on in your php.ini

Last edited by Jaffizzle; 06-01-05 at 05:46 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 06-01-05, 06:14 PM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
r u sure u can echo something after a header location? try removing the echo "...";
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 06-01-05, 06:25 PM
dennispopel dennispopel is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 263
Thanks: 0
Thanked 0 Times in 0 Posts
<?php
$test = "1";
echo "some text here..."; // After THIS there is no effect of the header() call
if($test == '1')
{
header("location: test2.php");
}
echo "...";
?>
__________________
onPHP5.com - PHP5: Articles, News, Tutorials, Interviews, Software and more
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 06-01-05, 06:27 PM
kalinchuk kalinchuk is offline
Wannabe Coder
 
Join Date: Jun 2004
Location: ...
Posts: 110
Thanks: 0
Thanked 0 Times in 0 Posts
but i need it there...
for the session, like this:
PHP Code:

<?php

echo "some txt here...";
session_start();
if(
$_SESSION['test'] == "")
{
header("Location: test2.php")
}
//if the session is not empty than continue writing stuff out
echo "blahblahblah";
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 06-01-05, 06:29 PM
Jaffizzle Jaffizzle is offline
Newbie Coder
 
Join Date: May 2005
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by dennispopel
<?php
$test = "1";
echo "some text here..."; // After THIS there is no effect of the header() call
if($test == '1')
{
header("location: test2.php");
}
echo "...";
?>

i thought the exact same thing!....but when i tested it, it actually worked.

I think its because the server im on has output_buffering enabled

Enables/disables output buffering. Output buffering enables you to send header lines (including cookies) even after you have sent the body content, however, PHP's output layer will be slowed down a bit. In addition to enabling/disabling output buffering for all files by setting this directive to ON/OFF, you can also selectively enable/disable output buffering at run time using the PHP functions ob_start, ob_end_clean, ob_end_flush, and ob_implicit_flush.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 06-01-05, 06:43 PM
Acecool's Avatar
Acecool Acecool is offline
Aspiring Coder
 
Join Date: Nov 2003
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
You cannot echo any text before header(), session_start(), setcookie() and other header functions.
__________________
Check Acecoolco.com for PHP Tutorials, and other tuts
If you plan on contacting me, please read this: Legal Terms & Conditions
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 06-01-05, 07:51 PM
kalinchuk kalinchuk is offline
Wannabe Coder
 
Join Date: Jun 2004
Location: ...
Posts: 110
Thanks: 0
Thanked 0 Times in 0 Posts
so, how do i redirect to a page anywhere in the code?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to create a header file in Visual C++? dummies_05 C/C++ 3 03-15-05 09:20 AM
Adding data to HTTP header perleo PHP 6 01-06-05 07:24 PM
Fsockopen Header Needed !! shadi PHP 3 12-10-04 03:08 AM
using function header() shadi PHP 2 08-14-04 04:55 AM
PHP header question khadlock PHP 2 09-23-03 09:17 AM


All times are GMT -5. The time now is 12:21 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.