 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
|
 |
|
 |
05-30-2008, 04:23 PM
|
#1 (permalink)
|
|
The Addict
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
|
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
|
|
|
|
05-30-2008, 04:32 PM
|
#2 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
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.

|
|
|
|
05-30-2008, 04:48 PM
|
#3 (permalink)
|
|
The Addict
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
|
Quote:
Originally Posted by delayedinsanity
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
|
|
|
|
05-30-2008, 05:24 PM
|
#4 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
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...
|
|
|
|
05-30-2008, 06:16 PM
|
#5 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
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)
|
|
|
|
05-30-2008, 06:56 PM
|
#6 (permalink)
|
|
The Addict
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
|
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
|
|
|
|
05-30-2008, 06:25 PM
|
#7 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
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
|
|
|
|
05-30-2008, 07:11 PM
|
#8 (permalink)
|
|
The Wanderer
Join Date: May 2008
Posts: 10
Thanks: 0
|
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
|
|
|
|
05-30-2008, 08:45 PM
|
#9 (permalink)
|
|
The Addict
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
|
Quote:
Originally Posted by Folio
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
|
|
|
|
05-30-2008, 10:24 PM
|
#10 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
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)
|
|
|
|
05-30-2008, 10:48 PM
|
#11 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
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.
|
|
|
|
05-31-2008, 02:41 PM
|
#12 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
It has to be a problem with the PHP installation. I can't see what else it could be.
|
|
|
|
06-01-2008, 05:51 PM
|
#13 (permalink)
|
|
The Addict
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
|
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
|
|
|
|
06-01-2008, 09:14 PM
|
#14 (permalink)
|
|
The Frequenter
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
|
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"
|
|
|
06-02-2008, 08:12 AM
|
#15 (permalink)
|
|
The Wanderer
Join Date: Mar 2008
Location: United Kingdom
Posts: 22
Thanks: 1
|
Are you sure the php code is above the html?
Are you sure the file is .php ?
|
|
|
06-02-2008, 04:23 PM
|
#16 (permalink)
|
|
The Contributor
Join Date: Jan 2008
Posts: 87
Thanks: 49
|
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?
|
|
|
|
06-02-2008, 04:40 PM
|
#17 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
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
|
|
|
|
|
The Following User Says Thank You to delayedinsanity For This Useful Post:
|
|
06-02-2008, 05:35 PM
|
#18 (permalink)
|
|
The Contributor
Join Date: Jan 2008
Posts: 87
Thanks: 49
|
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!
|
|
|
|
06-04-2008, 08:59 PM
|
#19 (permalink)
|
|
The Addict
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
|
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
|
|
|
|
06-04-2008, 09:28 PM
|
#20 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
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
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|