Page 1 of 2
heade(location) in a new window
Posted: Thu Jul 28, 2005 4:00 am
by hame22
Hi I am using the header(location:) fnction to redirect to a new page, is there a way I can get this page to load into a new browser rather than the original one.
I'm not sure whether it is possible using header but what about other options such as <META HTTP-EQUIV="refresh">??
thanks in advance
alex
Posted: Thu Jul 28, 2005 4:25 am
by timvw
It is the user that chooses where (in which window) a page is opened...
But you can use some JavaSCript window.open to manipulate that choice..
Posted: Thu Jul 28, 2005 5:20 am
by hame22
so there is no way in which the target can be included in the header code:
header("location: file_download.php?act_id=$act_id");
such as target = "blank"
???
thanks
alex
Posted: Thu Jul 28, 2005 5:53 am
by onion2k
no
Posted: Thu Jul 28, 2005 6:16 am
by pilau
So much of living up to your award, Onion

Posted: Thu Jul 28, 2005 6:50 am
by onion2k
pilau wrote:So much of living up to your award, Onion


Posted: Thu Jul 28, 2005 8:28 am
by theda
The thing is, most people hate having pop-ups and will trash a popup before they even finish loading. So chances are, you're visitors will do the same, so it's best to just let the visitors choose if they want it in a new tab (with ctrl or shift).
Posted: Thu Jul 28, 2005 8:45 am
by Chris Corbyn
If you learn about HTTP headers (Nothing to do with HTML itself) then you maybe see why it won't work.
The headers are sent before the content which the browser deals with.
header('Location: ....'); just sends a Location: ... header in the HTTP response and thus forces the browser to GET the content from somewhere else

Posted: Thu Jul 28, 2005 11:55 am
by br5dy
by the way, why ever use a header funciton to redirect when you could use javascript with much less pain?
Posted: Thu Jul 28, 2005 11:59 am
by nielsene
Because header doesn't require any "extra" client side technologies.
Posted: Thu Jul 28, 2005 12:02 pm
by Chris Corbyn
It's also more correct to do it using the HTTP protocol if they are being redirected rather than to send them a page which sends them to another page.
Posted: Thu Jul 28, 2005 12:33 pm
by josh
br5dy wrote:by the way, why ever use a header funciton to redirect when you could use javascript with much less pain?
What happens when javascript isn't enabled?
How is:
Code: Select all
header("location:http://example.com");
"much less pain" then
Code: Select all
echo ("<script>
window.location='http://example.com';
</script>");
In the latter you have more room for error, not only in your php script but the javascript itself could be erroneous.
Also a header redirect is more likely to redirect faster then a javascript redirect, especially if you're outputting a lot of html before the javascript.
Also javascript redirects are associated with 'doorways' and 'surfer traps' and could be red flagged by Google, where a header is just more "acceptable" by SE's, especially since a header is commonly used when renaming files (instead of a 404 many webmasters will leave the old file up and simply redirect it to the new page)
The javascript method is considered more spammy because when hitting the back button the user often gets fowarded, causing the spam site to receive a few extra page views before the user finally decides to manually type in the url he's trying to go back to (or hit the back button super super fast like 5 times)
Reason enough?
Posted: Thu Jul 28, 2005 1:44 pm
by br5dy
wasn't meant to be negative, i was just wondering.
Posted: Thu Jul 28, 2005 2:15 pm
by josh
br5dy wrote:wasn't meant to be negative, i was just wondering.
Just explaining, good question
Posted: Fri Jul 29, 2005 12:24 am
by br5dy
what i meant by much less pain, was that using headers in a multiple included php file is a pain because of the flushing the output buffer. don't you think?