Page 1 of 1
Redirecting in php

Posted:
Fri Jul 17, 2009 8:14 pm
by davidc538
- Code: Select all
header("Location: /surveys.php");
This line of code simply doesn't work, its driving me nuts. XAMPP is simply echoing
- Code: Select all
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\SSA\login.php:5) in C:\xampp\htdocs\SSA\login.php on line 17
AND I DON'T KNOW WHAT THE HELL IT MEANS!!!!:@:@:@
seriously though, if anyone can help me sort this out it'd be much appreciated
all i need to do is execute some code in php to send the user to another page of my choice
thanks in advance
Re: Redirecting in php

Posted:
Fri Jul 17, 2009 9:05 pm
by Blink
Are you declaring it before any other code in your page?
In my limited PHP experience if you try to declare PHP headers after the page has already requested them then you get issues.
Re: Redirecting in php

Posted:
Fri Jul 17, 2009 9:10 pm
by zombie@computer
headers are supposed to be the first thing you send to a browser, before the page's contents even get sent. Make sure you are not outputting any other data before the header() line(s)
Re: Redirecting in php

Posted:
Tue Jul 21, 2009 6:25 pm
by abathor
I thought you were supposed to use headers in PHP to redirect, like you are, I'm guessing, trying to do. It worked for me before, I'm pretty sure you can redirect from anywhere in the php, and that it doesn't have to be from the top of the page.
Re: Redirecting in php

Posted:
Tue Jul 21, 2009 6:30 pm
by zombie@computer
abathor wrote:I thought you were supposed to use headers in PHP to redirect, like you are, I'm guessing, trying to do. It worked for me before, I'm pretty sure you can redirect from anywhere in the php, and that it doesn't have to be from the top of the page.
you are wrong
php.net/manual/en/function.header.php
Re: Redirecting in php

Posted:
Tue Jul 21, 2009 8:29 pm
by Spirit55555
zombie@computer wrote:abathor wrote:I thought you were supposed to use headers in PHP to redirect, like you are, I'm guessing, trying to do. It worked for me before, I'm pretty sure you can redirect from anywhere in the php, and that it doesn't have to be from the top of the page.
you are wrong
php.net/manual/en/function.header.php
Not entirely...
You can use Output Buffering Control to send headers anywhere in PHP:
http://www.php.net/manual/en/book.outcontrol.php
Re: Redirecting in php

Posted:
Tue Jul 21, 2009 9:52 pm
by zombie@computer
Spirit55555 wrote:zombie@computer wrote:abathor wrote:I thought you were supposed to use headers in PHP to redirect, like you are, I'm guessing, trying to do. It worked for me before, I'm pretty sure you can redirect from anywhere in the php, and that it doesn't have to be from the top of the page.
you are wrong
php.net/manual/en/function.header.php
Not entirely...
You can use Output Buffering Control to send headers anywhere in PHP:
http://www.php.net/manual/en/book.outcontrol.php
Yes, well, you can calculate pi in php in seven hundred iterations and then header() redirect, as long as you dont send any output. Same for OB. I would hardly call that 'anywhere in the php'.
Re: Redirecting in php

Posted:
Mon Nov 30, 2009 8:13 am
by BruceSmith
Hi,
I got this problem and it took nearly 5 days to solve.
The function you wrote already seems error. There shouldn't be forward slash before file.
There should not be any space after the function. Try to remove semicolon after function.
I don't exactly what else I did. But I will soon clarify you.
Re: Redirecting in php

Posted:
Mon Nov 30, 2009 10:53 am
by Terr
As others have said, it's complaining because some of your code--or some code in whatever PHP framework you're running--has already sent off the batch of headers that web browsers expect first before anything else. There are other ways to do redirects (javascript and meta-refresh tags) but headers should generally be your first tool of choice.
Another thing to ensure is that there is no space--even blank space-- before your first <?php opening tag in the document. Because that suggests you want to sent one character of web-site content before even getting to your code.