|
Posted by David Haynes on 05/31/06 09:50
Toby Inkster wrote:
> David Haynes wrote:
>
>> <?php
>> /**
>> * Module: redirect.inc
>> *
>> * Manages a redirection when there may be a session active.
>> * Also correctly re-addresses URLs that are not absolute.
>> *
>> * @param string $url
>> */
>> function redirect($url) {
>> session_write_close();
>>
>> if( substr($url, 0, 4) != 'http' ) {
>> if( isset($_SERVER['HTTP_HOST']) ) {
>> $url = 'http://'.$_SERVER['HTTP_HOST'].$url;
>> } else {
>> $url = 'http://localhost'.$url;
>> }
>> }
>>
>> header("location: $url");
>> exit;
>> }
>> ?>
>
> redirect("http_1.1_spec.html");
>
> :-)
I use a convention that all urls in redirect must either be absolute or
start with /, but I see your point. substr($url, 0, 5) != 'http:' would
be better.
Thanks!
-david-
Navigation:
[Reply to this message]
|