duanliang8464 2013-11-13 16:11
浏览 126
已采纳

确定浏览器地址栏中的URL(不是真实地址)

I have two urls - biothoughtblog.co and playfight.co. The first is forwarding to the second and masking is used. I am using this

<?php
function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
?>

<?php
  echo curPageURL();
?>

on the page http://www.biothoughtblog.co/test.php - however, it echoes the real URL which is http://www.playfight.co/test.php. I need it to echo the URL that is in the address bar. I know very very little Javascript - is it what I need to be using here?

Thanks a lot.

P.S Oh, and the purpose is to run the same website under two different domains and different branding (logo, etc).

  • 写回答

2条回答 默认 最新

  • douwen7475 2013-11-13 16:13
    关注

    That's because http://www.biothoughtblog.co/test.php is framing http://www.playfight.co/test.php.

    <frame src="http://www.playfight.co/test.php" frameborder="0" />
    

    PHP has no way of knowing that it is loaded inside a frameset, and how to get the URL of the parent frame.

    You want to avoid using the "masking" feature of your registrar or DNS provider. Point the biothoughtblog.co domain to the same hosting server, ensure that your hosting account is setup for both domains. Then biothoughtblog.co wil be hitting your website directly, and PHP will know what it is.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?