|
-
Jan 9th, 2007, 02:20 PM
#1
Thread Starter
New Member
[RESOLVED] Browser redirection problem
Hey peepz
I can't find any info on this from 't3h g00gl3', and am in quite a rush to get this site finished, so I'll ask here:
It's come to my attention that you cannot redirect the browser to another site if the browser has already recieved HTML tags.
Q1, is this true? I guess so, as its not working for me
Q2: Is there a way around it?
Be sure that you do not have any text sent to the browser before this, or it will not work. Your safest bet is to simply remove all content from the page but the redirect code.
PHP Code:
<html>
<?php
//this will NOT work, the browser received the HTML tag before the script
header( 'Location: http://www.yoursite.com/new_page.html' ) ;
?>
Source: http://php.about.com/.../phpredirection.htm
Thanks
-
Jan 9th, 2007, 02:30 PM
#2
Re: Browser redirection problem
1) Yes.
2) Um, call header() and exit() before sending any output?
-
Jan 9th, 2007, 02:33 PM
#3
Re: Browser redirection problem
yes, it's true -- you can't send headers to a browser if the headers are already sent. once ANY output is given to the browser, headers have been sent.
there is a way around it, although it may not be the best way, but you can simply use output buffering. basically, what an output buffer does it hold the data and doesn't send anything to the browser until your you send the buffer to the browser itself. check out ob_start() to get started, on the left-hand side all of the relating buffer functions are there.
-
Jan 9th, 2007, 02:34 PM
#4
Re: Browser redirection problem
 Originally Posted by blowman
It's come to my attention that you cannot redirect the browser to another site if the browser has already recieved HTML tags
So... what do you think you should do? it can't work once they have seen sent you may try putting it before any content is sent
-
Jan 9th, 2007, 02:35 PM
#5
Re: Browser redirection problem
 Originally Posted by kows
there is a way around it, although it may not be the best way, but it does refrain from using javascript or anything like that to redirect instead. you can simply use output buffering -- and then if something unexpected happens (ie: login error, or some script error, or whatever), you can simply delete the buffer's contents and send a header to redirect somewhere instead.
That's a horrible retarded idea. Just do your logic processing before sending any output. Logic and presentation should always be kept completely separate.
-
Jan 9th, 2007, 02:38 PM
#6
Re: Browser redirection problem
oops, I edited my post before seeing anyone had replied.
either way, it's a work around. I already said it wasn't the best way. I've never had to do it, but it could be incredibly inconvenient to have to rewrite everything to do what you're planning on and I've had plenty of experiences where it would be great to use output buffering. there's other ways around it as well, output buffing is just one way. if you don't like it, don't do it!
-
Jan 9th, 2007, 03:32 PM
#7
Thread Starter
New Member
Re: Browser redirection problem
call header() and exit() before sending any output?
it can't work once they have seen sent you may try putting it before any content is sent
Just do your logic processing before sending any output.
Ok i have done this and it works, thanks. I should of realized that first, but its been a long day 
Thanks again for all your help people.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|