当前域上的元刷新
问题描述:
I'm trying to refresh page on the domain that it has been opened on, website can be accessed from multiple domains so I want to use the current one.
I tried
$url = "http://" . $_SERVER['HTTP_HOST'] . "/p.php" . "\">";
echo "<meta http-equiv=\"refresh\" content=\"0;url="; echo $url;
But that redirects me to: p.php without any domain, same result using $_SERVER['SERVER_NAME']
Not sure what I'm doing wrong ?
答
You don't need to use any $_SERVER
value. Just:
<meta http-equiv="refresh" content="0; url=/p.php">
The browser will use the same domain as the one it's currently visiting when it constructs the complete URL to which to redirect itself.
答
This might be a little long for your taste but here it is
// find out the domain:
$domain = $_SERVER['HTTP_HOST'];
// find out the path to the current file:
$path = $_SERVER['SCRIPT_NAME'];
// find out the QueryString:
$queryString = $_SERVER['QUERY_STRING'];
//Add parameters if any
if (!empty($queryString)) {
$queryString = "?" . $queryString;
}
// put it all together:
$url = "http://" . $domain . $path . $queryString;
?>
<meta http-equiv="refresh" content="0;url=<?php echo $url; ?>"