简体   繁体   English

当前站点的PHP Grab URL,但来自服务器上托管的主文件

[英]PHP Grab URL of Current Site, but from a master file hosted on a server

Hey guys basically I have a master file hosted on a server, and what it does is echo a list of links to a bunch of other sites. 大家好,基本上,我在服务器上托管了一个主文件,它的作用是回显指向其他站点的链接列表。 The set of links it grabs is based on the URL of the current site. 它获取的链接集基于当前站点的URL。 The problem I'm having is that using $_SERVER['REQUEST_URI'] on a server produces the url of that server and I want it produce the url of the site that my master page is loaded in to 我遇到的问题是,在服务器上使用$_SERVER['REQUEST_URI']会生成该服务器的url,而我希望它会生成将我的母版页加载到的网站的url。

<?php
$url = parse_url($_GET['url']); 
$str = $url['host']; 
echo $str; 
if ($str < "g"){ 
    //do stuff 
    echo(" has first character lower than g");
} 
else{ 
     echo(" has not first character lower than g"); 
}

?>

You would need to pass the client servers hostname into the $_GET['url'] then look for it in the [query] key outputted by parse_url($_GET['url']); 您需要将客户端服务器的主机名传递到$_GET['url']然后在parse_url($_GET['url']);输出的[query]键中查找它parse_url($_GET['url']);

<?php 
//client side host
file_get_contents('http://server.site.com/masterfile.php?url='.$_SERVER['HTTP_HOST']);
?>

If I understand you correctly. 如果我正确理解您的意思。 :s :s

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM