$ this-> input-> post()总是返回FALSE,由于不需要301 [英] $this->input->post() always returning FALSE, due to an unwanted 301

查看:143
本文介绍了$ this-> input-> post()总是返回FALSE,由于不需要301的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CodeIgniter的注册页面。 问题是,我的帖子数据无法通过。以下代码总是生成失败:

I'm working on a signup page in CodeIgniter. The problem is, my post data doesn't come through. The following code always produces 'fail':

class Signup extends CI_Controller {

    function index()
    {    
        if ($this->input->post())
        {
            echo 'success'; 
        }
        else
        {
            echo 'fail';

            echo form_open('signup');

            echo form_input('username', 'Username');
            echo form_input('email_address', 'Email address');
            echo form_submit('submit', 'Create Acccount');

            echo form_close();
        }
    }

}

可能的问题是什么?

为了使事情更有趣,在我的localhost表单工作正常。

To make matters even more interesting, on my localhost the form works just fine. It's when on the remote server when this fails.

更新1:根据要求,

<form accept-charset="utf-8" method="post" action="http://www.url.com/signup">
<input type="text" value="Username" name="username">
<input type="text" value="Email address" name="email_address">
<input type="submit" value="Create Account" name="submit">
</form>






更新2:我看到localhost和远程服务器之间的行为的另一个区别:当刷新(cmd R或F5)页面提交表单后,在本地主机上,我的浏览器要求我再次发送表单。远程服务器上的同一页面不会从浏览器调用这个问题,所以它看起来像一些重定向或url问题导致的问题?


Update 2: I see another difference in behavior between the localhost and the remote server: When refreshing (cmd R or F5) the page after submitting the form, on the local host my browser asks me to send the form again. The same page on the remote server doesn't invoke that question from the browser so it looks like some redirecting or url problem is causing the problem?

更新3:似乎在远程服务器上,用户被重定向的301.(永久移动)我还不知道这个重定向来自哪里。重定向有效地杀死后数据,因此它解释了为什么post()返回false。

Update 3: It appears that on the remote server, the user is being redirected by a 301. (moved permanently) I still have no idea where this redirect is coming from. The redirect effectively kills the post-data, so it explains why post() is returning false.

那么,有没有人知道我为什么要301'd?

更新4:我在CodeIgniter中重定向了我的base_url为 http://www.url.com ,而不是 http://url.com

Update 4: I got redirected within CodeIgniter by setting my base_url as http://www.url.com in stead of http://url.com

改变之后,它解决了问题! :)

After changing that, it solved the problem! :)

推荐答案

问题可能是由来自远程服务器的301重定向(位置HTTP头指令)引起的。如果你使用Firefox,你可以检查这个与插件TamperData。当然,您也可以查看 http://www.url.com/signup 在请求页面时是否重定向。

The problem could be caused by a 301 redirection (Location HTTP header directive) from the remote server. If you use Firefox, you could check for this with the plugin TamperData. Of course, you could also just see if http://www.url.com/signup gets redirected when requesting the page.

如果HTTP标头 Location http://url.com/signup (不含 www ),那么最简单的解决方案是对表单操作使用 http://url.com/signup 。请注意,如果表单位于同一服务器上,您也可以省略服务器地址。您可以改用 / signup

If the HTTP header Location is http://url.com/signup (without www), then the easiest solution is to use http://url.com/signup for the form action. Please note that you could also omit the server address if the form is on the same server. You could use /signup instead.

这篇关于$ this-&gt; input-&gt; post()总是返回FALSE,由于不需要301的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆