PHP 8.6.0 Beta 3 is available for testing

Yaf_Request_Abstract::getServer

(Yaf >=1.0.0)

Yaf_Request_Abstract::getServer检索 SERVER 变量

说明

public function Yaf_Request_Abstract::getServer(string $name, mixed $default = ?): mixed

检索一个 SERVER 变量。

参数

name

变量名。

default

当变量未找到时返回的值。

返回值

变量的值;如果未找到,则返回 default

示例

示例 #1 Yaf_Request_Abstract::getServer() 示例

<?php
class IndexController extends Yaf_Controller_Abstract
{
    public function indexAction()
    {
        $request = $this->getRequest();

        $host     = $request->getServer("HTTP_HOST");
        $protocol = $request->getServer("SERVER_PROTOCOL", "HTTP/1.1");

        var_dump($host, $protocol);
    }
}
?>

以上示例的输出类似于:

string(15) "www.example.com"
string(8) "HTTP/1.1"

参见

添加备注

用户贡献的备注

此页面尚无用户贡献的备注。
To Top