Forum Moderators: coopster

Message Too Old, No Replies

How many ways to do redirection via PHP?

         

irock

3:29 pm on Aug 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi, I am looking for a way to do URL redirection.

Beside this command, is there any other way to accomplish the same task?

header("location $url");

Thanks!

jatar_k

4:13 pm on Aug 26, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you could use meta refresh, you could do it with apache, you could even just include the desired content if it is on your site.

Why not header?

justageek

4:52 pm on Aug 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have to agree with jatar_k. Why not header. Been my my experience that it works all the time.

jonknee

11:27 pm on Aug 27, 2003 (gmt 0)

10+ Year Member



The only tricky bit with sending HTTP headers (AKA via header()) is that they MUST be sent out first. This is sometimes hard to add to existing scripts. Especially ones you didn't write.

Nisse

12:42 pm on Aug 29, 2003 (gmt 0)

10+ Year Member



Check out this function:

function redirect($url) {

if(headers_sent()) {

?>
<html><head>
<script language="javascript" type="text/javascript">
<!--
window.self.location='<?php print($url);?>';
//-->
</script>
</head></html>
<?
exit;

} else {

header("Location: ".$url);
exit;

}

}

Checks if headers are sent, javascript is used instead to do the redirection...