【问题标题】:codeigniter: why is codeigniter thinking the form is a get request instead of a post requestcodeigniter:为什么 codeigniter 认为表单是获取请求而不是发布请求
【发布时间】:2012-07-18 04:49:22
【问题描述】:

这是表格:

<?php echo form_open('locker_settingstwo/processform', array('class' => 'form-horizontal')); ?>
        <div class = "lockersettingstwodiv"> 
            <h2><?php echo $this->session->userdata('labelname'); ?></h2>
            <p> Control who can view/ReGemz the collection in this locker </p>
            <input type = "text" name = "testing" value = "" />
            <input type="radio" name="permission" value="1" /> Public - Others can view/edit this locker<br/>
            <input type="radio" name="permission" value="2" /> Me Only - Only you can view/edit this locker<br/>
            <input type="radio" name="permission" value="custom" /> Custom - Locked to everyone, meaning only friends I choose can view/edit this locker<br/>
        </div>
            <input type="submit" name = "Next" value="Next" class="btn btn-large btn-primary" style="margin-left: 0px; margin-top: 14px" />
            <input type="submit" name = "Cancel" value="Cancel" class="btn btn-large btn-primary" style="margin-left: 0px; margin-top: 14px" />
    <?php echo form_close(); ?>  

现在当我打印 $_SERVER['REQUEST_METHOD'] 时,它说的是 GET,而不是 POST...这是为什么呢?

这是表单发送到的控制器方法:

function processform() 
{
    echo $_SERVER['REQUEST_METHOD'];
} 

【问题讨论】:

  • 你什么时候打印 $_SERVER['REQUEST_METHOD'] ?
  • $this->input->server('REQUEST_METHOD') 返回什么?
  • form_open 默认使用 POST 方法,因此除非您在其他地方执行服务器请求方法,否则它不能使用。如果它实际上是 GET,那么一旦你在处理表单的文件上 print_r($_POST),你将不会得到任何东西。
  • 我总是接受,我不知道它不是更高..
  • @dave,接受你著名问题的答案,你可能会得到更多的人。

标签: php forms codeigniter post


【解决方案1】:

您的主机是如何设置的?有时当您使用 FastCGI SAPI 时,由于重定向/转发,POST 属性会被转换为 $_GET 超全局变量。

您使用的是什么 SAPI?

【讨论】:

  • SAPI = 服务器 API。使用这个:echo php_sapi_name();echo PHP_SAPI;
  • 为 echo php_sapi_name() 输出 cgi-fcgi
  • 那么cgi-fcgi到底是什么意思?
  • 您可以在此处阅读FastCGIen.wikipedia.org/wiki/FastCGI。它总是一本好书。简而言之,这就是网络服务器将接收到的信息传递给 PHP 的方式。有时,根据您使用的 SAPI,您需要以不同的方式访问数据。尝试查看您的数据是否进入脚本的方法是,运行 var_dump( get_defined_vars() );,它将显示 PHP 中所有已定义的变量。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-06
相关资源
最近更新 更多