I need to use header to redirect to another url, but i would prefer to use relative and not absolute urls.
How can i achieve this?
The code i have so far is
header("Location: http://" . $_SERVER['SERVER_NAME']
. dirname($_SERVER['PHP_SELF'])
. "/" . $relative_url);
But does it work if say, i specify relative url as
$relative_url = ../folder/filename.php
and then i use the header function
header("Location: http://" . $_SERVER['SERVER_NAME']
. dirname($_SERVER['PHP_SELF'])
. "/" . $relative_url);
Also, how can i make the http part to be auto-detected, incase the url starts with "http" or "https", as the above would only be useful for http.