【问题标题】:CodeIgniter POST variablesCodeIgniter POST 变量
【发布时间】:2011-07-21 12:53:01
【问题描述】:

任何人都知道为什么:

class Booking extends Controller {

    function booking()
    {
        parent::Controller();
    }

    function send_instant_to_paypal()
    {
        print_r($_POST);
        echo '<hr />';
        print_r($this->input->post());
        echo '<hr />';
        $id_booking = $this->input->post('id_booking');
        $title = $this->input->post('basket_description');
        $cost = ($this->input->post('fee_per_min') * $this->input->post('amount'));
        echo $id_booking;
        echo $title
        echo $cost
    }
}

将在 CI 中为 $_POST 回显 post 变量 但不适用于 $this->input->post();?

我有 $this->input->post() 正在使用并在网站其他地方的搜索页面上工作......但在这个页面上,它不起作用.. 这是我的表格...

这是精神上的;-p 有人发现我遗漏了什么明显愚蠢的东西吗?

【问题讨论】:

  • CI2.1 还是 CI1.X?看起来像 CI1,这意味着您对 $this->input-post() 的调用是错误的

标签: codeigniter post


【解决方案1】:

您很可能启用了 XSS 或 CSRF,它会禁止(在这里猜测)Paypal 将这些详细信息返回给您。

这是 CodeIgniter 的典型情况,并且有一些变通方法,例如为某些控制器排除 CSRF(通过配置或挂钩)。

如果您提供更多关于POST 来自何处的详细信息,我可以清楚地回答。

编辑

可能是您错误地调用了$this->input->post()?我知道 CI2.1 添加了对 $this->input->post() 的支持以返回完整的数组,但在此之前您必须明确定义您想要的 post 变量 ala:

$user = $this->input->post('username');

【讨论】:

  • 老实说,paypal 还没有进入循环(它会)。我所做的就是在视图中加载表单并发布到上面提供的控制器/方法。没有其他事情发生..我也将其分解为基础知识.. :-(
  • 我怀疑您将 CI2.1 文档(用户指南)与 CI1.X 版本混淆了,因此 $this->input->post() 不会为您返回数组。查看最新的更改日志:codeigniter.com/user_guide/changelog.html
  • 确实,这是一个新手错误。但是,我添加了显式的帖子变量,我已将其添加到我的第一篇帖子中。这些变量没有回响......我无法理解为什么......
【解决方案2】:

我通过排除该特定方法的 CSRF 保护解决了这个问题

您可以在 application/config/config.php 中添加此代码

if(stripos($_SERVER["REQUEST_URI"],'/Booking/send_instant_to_paypal') === FALSE)
{
    $config['csrf_protection'] = TRUE;
}
else
{
    $config['csrf_protection'] = FALSE;
}

【讨论】:

    【解决方案3】:

    我现在唯一能想到的是您可能没有加载表单助手,但我不确定它是否被用于此目的。 你可以在/config/autoload.php中做到这一点

    例如我有这个:

    $autoload['helper'] = array('url', 'form', 'html', 'site_helper', 'upload_helper');
    

    您也可以将其加载到您的函数本身中,如下所示:

    function send_instant_to_paypal()
        {
            $this->load->helper('form');
            print_r($_POST);
            echo '<hr />';
            print_r($this->input->post());
            echo '<hr />';
            $id_booking = $this->input->post('id_booking');
            $title = $this->input->post('basket_description');
            $cost = ($this->input->post('fee_per_min') * $this->input->post('amount'));
            echo $id_booking;
            echo $title
            echo $cost
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-15
      • 1970-01-01
      相关资源
      最近更新 更多