heade(location) in a new window

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

hame22
Forum Contributor
Posts: 214
Joined: Wed May 11, 2005 5:50 am

heade(location) in a new window

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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..
hame22
Forum Contributor
Posts: 214
Joined: Wed May 11, 2005 5:50 am

Post 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
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

no
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post by pilau »

So much of living up to your award, Onion :D
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

pilau wrote:So much of living up to your award, Onion :D
:D
theda
Forum Contributor
Posts: 332
Joined: Sat Feb 19, 2005 8:35 am
Location: USA

Post 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).
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 ;)
br5dy
Forum Newbie
Posts: 22
Joined: Sat Jul 23, 2005 2:52 pm

Post by br5dy »

by the way, why ever use a header funciton to redirect when you could use javascript with much less pain?
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Because header doesn't require any "extra" client side technologies.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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?
br5dy
Forum Newbie
Posts: 22
Joined: Sat Jul 23, 2005 2:52 pm

Post by br5dy »

wasn't meant to be negative, i was just wondering.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

br5dy wrote:wasn't meant to be negative, i was just wondering.
Just explaining, good question
br5dy
Forum Newbie
Posts: 22
Joined: Sat Jul 23, 2005 2:52 pm

Post 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?
Post Reply