Header function is making me crasy
Posted by: tunsiconet (196.203.155.---)
Date: October 23, 2007 09:21PM

Hello guys;
Sorry about this, I a beginner PHP developper, I need some help plase.
I wrote this script yesternight on my index.php file located under the apache directory directly,
<?php
ob_start();
header("Location: www.google.co.uk"winking smiley;
ob_flush_end();
?>

this script generates me a error pricising that the header are alredy sent, I copied the script created an other file named "test.php" and tried again over the new file, "THE SCRIPT WORKS CORRECTLY". so what's up now, do this script or doesn't it.

I noticed so, that no function that uses headers works on that file why "the index.php mistery". no session_start() no header() nothing.

For attention, I'm using wamp5 server in it's last version.
I worked with headers for a long time (with older versions of apache and php), I have not seen such problems.

So I'll be thankful, if any one can help.



Tounsi Moez
Genie Logiciel

Options: ReplyQuote
Re: Header function is making me crasy
Posted by: CyberSpatium (---.hsd1.or.comcast.net)
Date: October 26, 2007 05:08PM

you cannot have any kind of text, code, spaces,etc before a header



<?php
header("Location: www.google.co.uk"winking smiley;
?>



CyberSpatium
----------------------
WAMP English Forum Admin

I have WAMP5 working with (for development use only):
Windows Vista Ultimate x64 (64 bit)
Kaspersky Internet Security Suite 7.0.x
Spyware Terminater 2.x
CounterSpy 2.5.x


Need help? Check out my WAMP User Manual/Guide here!


Web Development for Newbie's Blog - Check out my new blog. It is for web developers, and especially tailored for the web development newbie. If you are not fluent in “geek speak”, then this incredible resource is just you. And even if you are a web development pro, this is a great resource to check out some of the latest web development tips, news, tutorials, codes and more.

Options: ReplyQuote
Re: Header function is making me crasy
Posted by: tunsiconet (196.203.144.---)
Date: October 26, 2007 10:36PM

But I have no kind of spaces, characters, ..
To use headers function they must be first lines of codes even befor html code.
An other alternative is to use output buffering like this way :
<?php
ob_start();
session_start();
header("Location: [www.google.com"]winking smiley;
ob_end_flush();
?>
notice here that I used two header functions in the same code, it's works perfectly everywhere, but the index.php file,

Strange isn't it.



Tounsi Moez
Genie Logiciel

Options: ReplyQuote
Re: Header function is making me crasy
Posted by: CyberSpatium (---.hsd1.or.comcast.net)
Date: October 27, 2007 10:49PM

as i stated before, you cannot put anything (code, text, spaces, etc) before your header() command. you cannot use output buffering here. it causes a header already sent error because the ob_start() code has already been executed. remove the output buffering code on your script and you will be fine,



CyberSpatium
----------------------
WAMP English Forum Admin

I have WAMP5 working with (for development use only):
Windows Vista Ultimate x64 (64 bit)
Kaspersky Internet Security Suite 7.0.x
Spyware Terminater 2.x
CounterSpy 2.5.x


Need help? Check out my WAMP User Manual/Guide here!


Web Development for Newbie's Blog - Check out my new blog. It is for web developers, and especially tailored for the web development newbie. If you are not fluent in “geek speak”, then this incredible resource is just you. And even if you are a web development pro, this is a great resource to check out some of the latest web development tips, news, tutorials, codes and more.

Options: ReplyQuote


Sorry, only registered users may post in this forum.