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).
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;
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With