返回HTTP/HTTPS协议
我,我从什么地方得到了下面的代码,它似乎并没有被工作:返回HTTP/HTTPS协议
function http() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
return $http;
}
有人能帮忙吗?
什么,我试图做的是返回网站协议时,我输入$
前的http:
<a href="<?php echo $http . $websiteurl .'/index.php' ?>">Website URL including Protocol</a>
我已经得到了$ websiteurl下来,我似乎无法让它回应http与https。我不太了解功能,所以我不知道如何解决它。
的http
是一个函数,所以你不要这样称呼它采用可变$
尝试:
function http() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
return $pageURL; // <-changed
}
<a href="<?php echo http() . $websiteurl . '/index.php'; ?>">Website URL including Protocol</a>
澄清:
$http = 'variable';
function http() {
return 'function';
}
var_dump($http);
var_dump(http());
+ 1为捕捉这两个明显的错误,虽然你的'澄清'似乎没有什么帮助。 – 2013-03-18 15:11:53
你说得对。如果你了解澄清,你可能并不需要它。 – 2013-03-18 15:14:51
太棒了,除了......当我做URL并点击链接......它会在所有的网址中留下:除了冒号之外,它正在通过一切。当我回显出http()时,冒号就在那里。我该如何解决? – kdjernigan 2013-03-18 15:18:19
您试图通过$http
得到http()
的值。仅在http()
功能的范围定义
<a href="<?php echo http() . $websiteurl .'/index.php' ?>">Website URL including Protocol</a>
$http
:试试这个。
<a href="<?php echo http() . $websiteurl .'/index.php' ?>">Website URL including Protocol</a>
功能将触发E_NOTICE
错误原因是,试试这个:
function http() {
return (getenv('HTTPS') == "on" ? 'https://' : 'http://');
}
然后作为mkjasinski说`的,
<a href="<?php echo http() . $websiteurl .'/index.php'; ?>">Website URL including Protocol</a>
什么是E_NOTICE错误?为什么会触发它们? – kdjernigan 2013-03-18 15:20:23
使用'HTTP()代替'$ http'。 – zneak 2013-03-18 15:05:09
不需要使用// http://stackoverflow.com/questions/12069156/protocol-less-urls – Waygood 2013-03-18 15:05:18
'$ http'永远不会被定义(无论是在函数还是在其他代码中) – str 2013-03-18 15:05:32