Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

redirecting 1

Status
Not open for further replies.

TheConeHead

Programmer
Aug 14, 2002
2,106
US
is it possible to redirect from within php? or does it need to be done in the html?

[conehead]
 
header("Location:TheLocation");

Known is handfull, Unknown is worldfull
 
You need some extra to that header:
Code:
header("HTTP/1.1 301 Moved Permanently"); 
header("location: [URL unfurl="true"]http://www.domain.tld/");[/URL] 
header("Connection: close");

The connection:close, is needed, so some IE versions do not freeze.

Also, the 301 is so that google, and others, will not penalize your page!

If you want a redirection, with a timeout, you have to use the meta-refresh. But: Beware, meta-refresh with low timeout, will also get your site penalized!

Here is a skeleton which you might enjoy:
Code:
<?php 
function redir($goto = 404, $timeout = 0, $basepath = "") { 
  if(is_file($basepath . $goto)) { 
    if($timeout == 0) { 
      echo "header:location"; 
    } 
    else { 
      echo "meta refresh"; 
    } 
  } 
    else { 
      echo "Sorry, the file was not found!"; 
    } 
} // end function re_dir 
?>

ps. I did not test that code, so it might be a bit buggy.

Olav Alexander Mjelde
Admin & Webmaster
 
is there a way to do it where it does not have to be at the top of the page? I am looking for something like asp's response.redirect() which can be used anywhere in the page

[conehead]
 
DaButcher, here is a star for the useful info. Could you touch on the Google penalizing more? Sorry conehead, not trying to take your post...

Cone - you'll need to do your testing and functionality before anything is written to the client. It doesn't necessarily have to be at the TOP of the page, but it must be before any html is sent (which includes whitespace).

*cLFlaVA
----------------------------
[tt]insert funny quotation here.[/tt]
 
There are a few sites that list things that you can get penalized for using google. The one available to webmasters on google is here:
A FAQ with some useful information is here:
And this is a webmaster guide that is not google, but has useful tips for webmasters, regarding some of the things you can get penalized for:
This is getting a little off topic though, I'll start a new thread with this information as well.
 
Thank you, Cflava.
I dont remember where I first read about penalizing, but if you google for it, you can find a lot of threads about it.

I think that a lot of people are not aware of penalizing or the PR-Ranking.

You can actually calculate your PR-ranking, based on several factors.
I'm sorry that I dont have any url to give you now.. I'll post back here later, if I stumble across any.

I dont have time enough to search for them now, as I was just packing christmas-presents.

Happy christmas/x-mas/hannukah(?)!

Olav Alexander Mjelde
Admin & Webmaster
 
hannukah(?)
why the "?"?

--Chessbot

There is a level of Hell reserved for probability theorists in which every monkey that types on a typewriter produces a Shakespearean sonnet.
 
I'm not sure how to spell it, and someone told me that hannukah is not at the same time as christmas?

I was told it was in march/april or something, while I thought it was when we had christmas.

Olav Alexander Mjelde
Admin & Webmaster
 
hannukah is very close to christmas. i think it finished a week or two ago.

*cLFlaVA
----------------------------
[tt]insert funny quotation here.[/tt]
 
Hannukah is celebrated on the 25th of Kislev on the Jewish calendar. Since the Jewish calendar a Lunar calendar, extra months get added during leap years which skews the date of Hannukah on the Gregorian Calendar. It usually hits around the same time as Christmas, but can start as early as the end of November or as late as the end of December.

Next year it starts on December 26th.

Ken
 
Ah, someone else who knows.
Hanukah can also be spelled any way that you want. Some common variants:
Hanuka Chanuka
Hannuka Channuka
Hanukka Chanukka
Hannukka Channukka
Hanukah Chanukah
Hanukkah Chanukkah
Hannukah Channukah
Hannukkah Channukkah

This year, it was sunset on the 7th to sunset on the 14st (if I remember correctly).

--Chessbot

There is a level of Hell reserved for probability theorists in which every monkey that types on a typewriter produces a Shakespearean sonnet.
 
Now that this post is completely off topic ;)

I just toss in a little javascript snippet if I want to redirect post header(I suppose you could make this a function if you use it a lot)...

Code:
?>
<script type="text/javascript">
setTimeout(\'window.location="[URL unfurl="true"]http://www.yourpagehere.com/"\',2000);[/URL]
</script>
<h3>You will be redirected to blah blah blah in 2 seconds</h3>
<?php
 
Actually, I have found that using location.replace(url) seems to be more widely accepted than location = url or any variant.

But then again, I like to be picky ;-)

--Chessbot

There is a level of Hell reserved for probability theorists in which every monkey that types on a typewriter produces a Shakespearean sonnet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top