RE: antti at haapakangas dot net's post
I've changed the code so $_SERVER['SERVER_NAME'] is used if $_SERVER['HTTP_HOST'] is not set. $_SERVER['SERVER_NAME'] doesn't meet my needs, but I suppose it's good to fall back on it. I've also fixed a problem in the meta refresh line - it was missing the "url=" part of the content attribute.
<?php
function server_url()
{
$proto = "http" .
((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "s" : "") . "://";
$server = isset($_SERVER['HTTP_HOST']) ?
$_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
return $proto . $server;
}
function redirect_rel($relative_url)
{
$url = server_url() . dirname($_SERVER['PHP_SELF']) . "/" . $relative_url;
if (!headers_sent())
{
header("Location: $url");
}
else
{
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\">\r\n";
}
}
?>