TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 05-30-2008, 04:23 PM   #1 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default header() function wont work

this is the only peice of code im putting on our server

Code:
<?php
header("Location: http://www.yahoo.com");
?>
and im getting this error

Code:
Warning: Cannot modify header information - headers already sent by (output started at /status/test.php:1) in /status/test.php on line 2
what can cause this? im going crazy
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 05-30-2008, 04:32 PM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Well now, what you have there is ultimately one of the rarest problems ever to happen to a PHP script. I'm not sure, but I think the script may be sending some whitespace before the header is sent somehow. Make sure there's no spaces or tabs before the opening <?php token.
delayedinsanity is offline  
Reply With Quote
Old 05-30-2008, 04:48 PM   #3 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

Quote:
Originally Posted by delayedinsanity View Post
Well now, what you have there is ultimately one of the rarest problems ever to happen to a PHP script. I'm not sure, but I think the script may be sending some whitespace before the header is sent somehow. Make sure there's no spaces or tabs before the opening <?php token.
nope no white space that is the onyl peice of code i have in a test.php file.

how can i tell what headers are being sent out?

i tried putting flush(); and ob_flush(); but nothing happends.
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 05-30-2008, 05:24 PM   #4 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

Wow, this is an odd problem. If I was at home right now I would fool around with it, but because I'm not at home...
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 05-30-2008, 06:16 PM   #5 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

PHP Code:
<?php
ob_start
();
header("Location: http://www.yahoo.com");
ob_end_flush();
that should work, no reason i can think of why it wouldn't.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 05-30-2008, 06:25 PM   #6 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Quote:
that should work, no reason i can think of why it wouldn't.
I can think of a few.
  • you're using ASP.
  • you wrote it on paper
  • there's bubblegum in the server
...hopefully you never have to experience any of these situations though.
-m
delayedinsanity is offline  
Reply With Quote
Old 05-30-2008, 06:56 PM   #7 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

Code:
<?php
ob_start();
header("Location: http://www.yahoo.com");
ob_end_flush();
?>


Code:
Warning: Cannot modify header information - headers already sent by (output started at status/test.php:1) in status/test.php on line 3
didnt work, is there any other way to see what headers are sent?

ps: this is on a linux server

what phpinfo do you want me to post
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 05-30-2008, 07:11 PM   #8 (permalink)
The Wanderer
 
Join Date: May 2008
Posts: 10
Thanks: 0
Folio is on a distinguished road
Default

maybe a prepend?
is this file being included by another file?

you could also try redirecting the page via javascript if the problem persists. it is a strange one though
Folio is offline  
Reply With Quote
Old 05-30-2008, 08:45 PM   #9 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

Quote:
Originally Posted by Folio View Post
maybe a prepend?
is this file being included by another file?

you could also try redirecting the page via javascript if the problem persists. it is a strange one though
nope, the file is as is, no includes or anything.
i sent an email to our server admin to see if they have restricted header modification or something.

yea i can do javascript but im creating ag login script and if i did use js to redirect a user from being able to see important data , if they disable js they can penetrate through and view info.

my script wasnt working at first i kept getting a bunch of header errors and when i tried using the header function alone on a new sheet i noticed it wouldnt work. so ill find out and keep u guys posted to learn something new :p
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 05-30-2008, 10:24 PM   #10 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

tis indeed an odd one, interesting to see what the problem is.

Good luck.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 05-30-2008, 10:48 PM   #11 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Check the encoding of the file, I've known this to occur when the server thought it was encoded in something it wasn't. Aside from that, there's the other option of missing something really simple and obvious but we've covered those things already.
Salathe is offline  
Reply With Quote
Old 05-31-2008, 02:41 PM   #12 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

It has to be a problem with the PHP installation. I can't see what else it could be.
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 06-01-2008, 05:51 PM   #13 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

i sent an email to the service host and see what they say, i'll let you guys know.

yea it is a weird one, never saw anything like it b4.
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 06-01-2008, 09:14 PM   #14 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

Not to defy other solutions, but above the <?php tag, is there ANY output? Even when it's included into an other file?
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Old 06-02-2008, 08:12 AM   #15 (permalink)
The Wanderer
 
Join Date: Mar 2008
Location: United Kingdom
Posts: 22
Thanks: 1
boycoda is on a distinguished road
Default

Are you sure the php code is above the html?

Are you sure the file is .php ?
Send a message via MSN to boycoda Send a message via Skype™ to boycoda
boycoda is offline  
Reply With Quote
Old 06-02-2008, 04:23 PM   #16 (permalink)
The Contributor
 
Join Date: Jan 2008
Posts: 87
Thanks: 49
StevenF is on a distinguished road
Default

I have the exact same error. I know headers should be sent out before anything else on the page, but the way my page is structures and designed, I need it to be half way through my code. I have the following after a form:

PHP Code:
//Cary out the following query if the person updates cart
                    
if (isset($_POST['update_cart']))
                    {
                        
            
                        
//Update quantity
                        
$update_query 'UPDATE cart SET     pass_quantity = "'.mysql_real_escape_string($show_quantity).'"
                                                            WHERE pass_cdID = '
.$stored_cdID
                        
mysql_query($update_query);
                            
                        
//Refresh page and display the following
                        
header('Refresh: 1; url=cart.php');
                        echo (
"Cart Updated!");
                        
                    } 
And get the same error. Is there any other way to do what I'm doing other than header?
__________________
My Personal and Photo Blog
StevenF is offline  
Reply With Quote
Old 06-02-2008, 04:40 PM   #17 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

If the result of the form being processed is that you're forwarding the user to another page, why not place it at the top?

PHP Code:
<?php
if (isset($_POST['update_cart'])) {
// do your stuff and redirect
}
?>
<html> ... do your other stuff .. </html>
This also has the bonus that if you want to display an error message on the form, you can set one at the top of the page that will be displayed later on only if it's found to be set.
-m
delayedinsanity is offline  
Reply With Quote
The Following User Says Thank You to delayedinsanity For This Useful Post:
StevenF (06-02-2008)
Old 06-02-2008, 05:35 PM   #18 (permalink)
The Contributor
 
Join Date: Jan 2008
Posts: 87
Thanks: 49
StevenF is on a distinguished road
Default

Thanks Delay, I totally forgot that all PHP is dealt with before HTML. I was thinking it had to be where it was because it wouldn't know if "update_cart" existed. It also allowed me to display the error in a nice spot within the content.

However, I have moved it to the top of the page and everything is working fine - thanks!
__________________
My Personal and Photo Blog
StevenF is offline  
Reply With Quote
Old 06-04-2008, 08:59 PM   #19 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

i found the garbage that was being sent out in the header i did this

Code:
<?php echo headers_sent(); ?>
on the first line of the page

and i get a number 1 value but i cant figure out where its coming from.
it doesnt exist anywhere. i have done a search all over for it.

i tried using ob_flush() and flush() but nothing happends. how can i clear it?


if i tried something like

Code:
if (headers_sent() == TRUE) { clear headers }
i also tried this
Code:
var_dump(headers_sent());
and i get this outputed --> bool(true)
how can that be done? thanks
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 06-04-2008, 09:28 PM   #20 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

That's wierd. I tried
PHP Code:

1
<?php var_dump(headers_sent()); ?>
... the text is there to make sure it had to send some kind of header, and I still get bool(false). Not a very handy function if it doesn't tell the truth!! I just tried adding a specified header() Content-Type before the var_dump and it still outputs as false for me. That's handicapped.
-m
delayedinsanity is offline  
Reply With Quote
Reply



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

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


All times are GMT. The time now is 02:02 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design