判断项目中当前url是http还是https
我有一个 Zend 框架的网站。这里我想识别当前的URL是包含HTTPS还是HTTP?我使用了以下代码
if($_SERVER['HTTPS']==on){ echo "something";}else{ echo "something other";}
,但结果不正确。有没有其他方法可以识别这个? 另外我还有一个问题。 如何使用php获取完整的当前url(包括HTTP/HTTPS)?
请帮助我
提前致谢
I have a website in Zend framework. Here I want to identify whether the current URL contains HTTPS or HTTP? I have used the following code
if($_SERVER['HTTPS']==on){ echo "something";}else{ echo "something other";}
But the result is not correct. Is there is any other way to identify this?
Also I have one more question.
How to get complete current url (including HTTP/HTTPS) using php?
Please help me
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
请注意
on
应该是一个 string 。notice the
on
should be a string .您可以使用 Zend Framework 中已定义的方法,而不是显式使用
$_SERVER
超全局变量。要确定连接是 HTTP 还是 HTTPS(此代码应进入您的控制器):
要获取完整的当前 url:
You could use methods that are already defined in Zend Framework instead of explicitly using
$_SERVER
superglobals.To determine if the connection is HTTP or HTTPS (this code should go into your controller):
To get complete current url:
更好的检查方法是
按照手册中所述
The better way to check is
As stated in manual
您需要修复检查它应该是
或尝试以下功能
you need to fix check it should be
or try following function
这将检查您是否使用 https 或 http 并输出当前 url。
This will both check if you're using https or http and output the current url.