dqo88037 2013-08-25 19:27
浏览 42
已采纳

YII提出的安全Ajax请求

i'm currently writing a Application based on YII.
My action for index:

  public function actionIndex() {
    $data = array();
    $data['server'] = Server::model()->findByPk(1);
    $data['dataProvider'] = new CActiveDataProvider('ServerUserPermission', array('criteria' => array('condition' => 'serverID=:id', 'params' => array(':id' => 1))));
    $this->render('index', $data);
}

my ajax action:

public function actionAddPermission($server) {
    if(Util::checkServerPower($server, Permission::MODIFY_SERVER)) {
        $perm = new ServerUserPermission;
        $perm->userID = 1;
        $perm->serverID = $server;
        $perm->power = 10;
        try {
            if ($perm->save()) {
                echo "OK";
            } else {
                echo Util::print_r($perm->getErrors());
            }
        } catch (Exception $e) {
            echo 'Critical Error Code: ' . $e->getCode();
        }
    } else {
        echo 'No Permissions';
    }
}

My view links to the addPermission action by using a button:

echo CHtml::ajaxButton("Insert New Player", array('addPermission', 'server' => $server->serverID), array('success'=>'refresh')); 

My function Util::checkServerPower(...) checks the current User of the Application. Consequence: Ajax requests in YII are handled by an Guest AuthWeb User, but i need to check whether the User is actually allowed to add permissions or not. I currently cannot think of a secured solution to protect malicious data send by other guests or not. Is it somehow possible to get the (server-side) userID of the Ajax-call?

Thanks anyway sincerly

  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥100 制作短链接和api接口的
      • ¥15 星河亮点sp9500测试指导
      • ¥15 dataframe 某列数据分列
      • ¥15 风扇导入fluent后仿真压力和速度数据卡在旋转域
      • ¥15 echarts中dataZoom报错
      • ¥15 求解答:《前端综合基础》作为一门课程的话,应该包含哪些内容?
      • ¥15 软件原型系统开发+实例测试
      • ¥50 C#上位机调试Win USB
      • ¥15 java基础望榜榜 java基础望榜榜
      • ¥15 comsol 周期性端口