Security 在Zend应用程序中处理无效输入的最安全的方法是什么?
我有一个应用程序,用户从包含ID值的链接(例如:/students/view/42)到达页面。在我的代码中,我使用Zend_Filter_输入,如下所示:Security 在Zend应用程序中处理无效输入的最安全的方法是什么?,security,validation,zend-framework,error-handling,zend-filter,Security,Validation,Zend Framework,Error Handling,Zend Filter,我有一个应用程序,用户从包含ID值的链接(例如:/students/view/42)到达页面。在我的代码中,我使用Zend_Filter_输入,如下所示: $input = new Zend_Filter_Input(array(), array( 'id' => new Zend_Validate_Db_RecordExists(array ( 'table' => 'Students', 'field' => 'id' )
$input = new Zend_Filter_Input(array(), array(
'id' => new Zend_Validate_Db_RecordExists(array (
'table' => 'Students',
'field' => 'id'
)
), $this->_request->getParams());
if (!$input->isValid()) {
// ???
}
$this->getResponse()->setHttpResponseCode(404);
我不认为在这一点上有任何惊天动地的事情发生。但是,我不清楚的是,如果id的值无效,该怎么办
在他的书《Zend框架:初学者指南》中,Vikram Vaswani让用户抛出一个异常(Zend_Controller_Action_exception('Page Not Found',404))。这是处理此问题的最佳方法吗?如果不是,还有哪些其他选项可用?您应该将用户重定向到包含404错误描述的页面(您应该使用ErrorController呈现异常消息)或包含该学生不存在的消息的特定页面 只需抛出异常并在ErrorController中呈现错误页面 您可以这样做:
$input = new Zend_Filter_Input(array(), array(
'id' => new Zend_Validate_Db_RecordExists(array (
'table' => 'Students',
'field' => 'id'
)
), $this->_request->getParams());
if (!$input->isValid()) {
// ???
}
$this->getResponse()->setHttpResponseCode(404);
或
典型的ErrorController类如下所示:
class ErrorController extends Zend_Controller_Action
{
public function errorAction()
{
$errors = $this->_getParam('error_handler');
switch ($errors->type) {
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
// 404 error -- controller or action not found
$this->getResponse()
->setRawHeader('HTTP/1.1 404 Not Found');
// ... get some output to display...
break;
default:
// application error; display error page, but don't
// change status code
break;
}
}
}
酷。现在来看下一个问题:我该怎么做?我尝试了以下代码,但没有成功:$this->u response->clearBody()$此->_响应->clearHeaders()$此->\u响应->设置HttpResponseCode(404);