public function redirectToCas($gateway=false,$renew=false)
{
phpCAS::traceBegin();
$cas_url = $this->getServerLoginURL($gateway, $renew);
session_write_close();
if (php_sapi_name() === 'cli') {
@header('Location: '.$cas_url);
} else {
header('Location: '.$cas_url);
}
phpCAS::trace("Redirect to : ".$cas_url);
$lang = $this->getLangObj();
$this->printHTMLHeader($lang->getAuthenticationWanted());
$this->printf('<p>'. $lang->getShouldHaveBeenRedirected(). '</p>', $cas_url);
$this->printHTMLFooter();
phpCAS::traceExit();
throw new CAS_GracefullTerminationException();
}
項目需要實現(xiàn)單點登錄,用的是apereo/phpcas這個包,但是執(zhí)行到跳轉(zhuǎn)到cas服務(wù)器的時候,header執(zhí)行不了,也就是上面這個
if (php_sapi_name() === 'cli') {
@header('Location: '.$cas_url);
} else {
header('Location: '.$cas_url);
}
位置,其中webman是cli模式。
有好的解決方案么?
搜了下,header在cli模式下不可用。
仔細看下文檔 http://wtbis.cn/doc/webman/response.html
function redirect($location, $status = 302, $headers = [])
{
$response = new Response($status, ['Location' => $location]);
if (!empty($headers)) {
$response->withHeaders($headers);
}
return $response;
}