Reputation: 33
Right now I have this:
header("Refresh: 0; url=http://192.168.100.100:10500/redirect2.php");
How can I do the same redirect but without writing address, only port? Both files are in the same folder on the same server.
The thing is that I don't know the address that will be used to access this server (private or public).
Upvotes: 3
Views: 7331
Reputation: 1012
Maybe it's be useful for someone, isHttps() function can detect SSL.
function isHttps() {
return
(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')
|| $_SERVER['SERVER_PORT'] == 443;
}
$destinationPort = '10500';
$schema = isHttps() ? "https" : "http";
$schema .= "://";
header('Location: ' . $schema . $_SERVER['HTTP_HOST'] . ':' . $port
. $_SERVER['REQUEST_URI']);
exit;
Upvotes: 1
Reputation: 32260
Use the superglobal $_SERVER
array, Location
header and exit;
$port = '10500';
header('Location: '
. ($_SERVER['HTTPS'] ? 'https' : 'http')
. '://' . $_SERVER['HTTP_HOST'] . ':' . $port
. $_SERVER['REQUEST_URI']);
exit;
Upvotes: 6