PHP 确定当前 url
我需要修改我的函数以返回我所在的当前文件夹。这是我当前的函数:
function getLinkFromHost($url){
$port = $_SERVER['REMOTE_PORT'];
$server = $_SERVER['HTTP_HOST'];
if($port == 443){
$type = "https";
} else {
$type = "http";
}
return $type . "://" . $server . "/" . $url;
}
I need to modify my function to return also the current folder I am in. Here is my current function:
function getLinkFromHost($url){
$port = $_SERVER['REMOTE_PORT'];
$server = $_SERVER['HTTP_HOST'];
if($port == 443){
$type = "https";
} else {
$type = "http";
}
return $type . "://" . $server . "/" . $url;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
查看
$_SERVER['REQUEST_URI']
或$_SERVER['SCRIPT_NAME']
(来自
$_SERVER
手动输入)Take a look at
$_SERVER['REQUEST_URI']
or$_SERVER['SCRIPT_NAME']
(From the
$_SERVER
manual entry)这是一个简短而甜蜜的函数,我已经用它来做这件事有一段时间了。
我不能相信,它属于:
http://www.webcheatsheet.com/ PHP/get_current_page_url.php
Here a short sweet function I've been using to do this for awhile now.
I can't take the credit, it belongs to:
http://www.webcheatsheet.com/PHP/get_current_page_url.php
也许您还想将 get vars 包含到您的网址中,因此您应该向 highphilosopher 函数添加一些内容...
$current_url = rtrim(curPageURL(), "/").(!empty ($_GET)) ? "?".http_build_query($_GET) : "";
Probably you also want to include get vars into your url, so you should add something to highphilosopher function...
$current_url = rtrim(curPageURL(), "/").(!empty($_GET)) ? "?".http_build_query($_GET) : "";
…………
..........
这是一个可能有帮助的方法:
Here's a method that might help: