【问题标题】:Preventing access to subsequent pages not proceeding current防止访问未进行当前的后续页面
【发布时间】:2013-05-03 07:56:37
【问题描述】:

我有一个 codeigniter MVC 设置,其中一个表单存在于一个页面上。

每次用户点击提交按钮时,同一个控制器在相同的 url http://domain.com/form 下加载下一块表单,并使用相同的视图但具有不同的数据(本例中的数据是表单元素)。

目标:

1) 确保加载的下一个部分是正确的进行部分。 请记住,我在同一个 URL 下使用同一个控制器,并且我使用同一个视图,只是每次需要填充一个新控制器时使用不同的初始化数据。

2) 限制用户跳转到不直接继续他当前正在处理的表单块

完成此任务的最佳方法是什么?我想使用会话,但不想使用隐藏的输入元素。

【问题讨论】:

    标签: php forms codeigniter session access-control


    【解决方案1】:

    可能是这样的:

    // load first form data here, then: 
    $data = '...';
    
    // this is intentionally above the first form
    if ($this->session->userdata('step_1') == 'done' AND is post action) {
       if(the second form is validated, then) {
           // unset the session here
           $this->session->unset_userdata('step_1');
       }
    }
    
    if ($this->session->userdata('step_1')!=='done' AND is post action ) {
        if(the first form validates here, then) {
           $this->session->set_userdata('step_1', 'done');
           // prepare the second form data here, that will override the one above:
           $data = '...';
        }
    }
    

    请注意,我有一段时间没有使用 CI,所以我不太记得那里的所有对象名称,但你应该明白这一点。

    【讨论】:

    • 嗨,这怎么能做到the first form is validated?我能想到的唯一方法是使用键在表单 1 上设置隐藏输入。但这是我想避免的事情。如果验证依赖于发布操作,那么用户可以使用包含this is the first form you can trust mei'm the last form go ahead and post this incomplete data to your databse moahahahahah 的发布正文模拟对我的服务器的发布请求。
    • 请看我编辑的答案,现在应该清楚如何查看第一个表单是否已标记为已验证。
    猜你喜欢
    • 2019-10-24
    • 2014-07-15
    • 2014-07-20
    • 2018-07-07
    • 2010-11-05
    • 2010-09-16
    • 1970-01-01
    • 1970-01-01
    • 2013-09-27
    相关资源
    最近更新 更多