【问题标题】:Base_url() is adding unnecessary segments into my url?Base_url() 在我的 url 中添加了不必要的段?
【发布时间】:2014-05-31 21:19:10
【问题描述】:

我的 base_url() 在 url 中添加了比应有的更多位。我的设置有什么问题?我在 config.php 中设置了助手:

$autoload['helper'] = array('url');

我的 base_url() 设置为:index.php/

所以问题是当我激活这个表单时:

<h1>sometimes haikus don't make sense refrigerator</h1>
<form action="<?php echo base_url(); ?>welcome/login_submit" method="post">
    <label>
        email:
        <input id="email" name="email" />
    </label>
    <label>
        password:
        <input type="password" id="password" name="password" />
    </label>
    <input type="submit" value="Log me in!" />
</form>

我第一次访问它时,我会输入:localhost/CIintranet/,接下来会添加 base_url(),所以它变成:localhost/CIintranet/index.php/

我正在尝试编写一个登录注销系统。因此,如果用户登录不正确,我希望它重定向回登录页面。这是该部分控制器的代码:

public function login_submit() {
        $this->load->model('LoginChecker', 'users');
        //$this->load->view('login_submit');

        $match = $this->users->authenticate_user( $_POST['email'], $_POST['password'] );
        if( $match )
        {
            $this->load->view('login_submit');
            echo "User exists in database!";
        }
        else
        {
            $this->load->view('login_form');
            echo "<h1>Email or password is wrong, bretheren!</h1>";
        }
    }

但是当它重新加载 login_form 时,它会在 url 中添加另一部分并且 url 失败。所以进度是这样的:

页面加载到这个网址:

localhost/CIintranet/

第一次尝试失败(页面仍然正常加载):

localhost/CIintranet/index.php/welcome/login_submit

第二次尝试失败(页面加载失败):

localhost/CIintranet/index.php/welcome/index.php/welcome/login_submit 

我已经对此进行了一些研究,我注意到很多人都在谈论与此问题相关的 htaccess 文件,但似乎没有人具体提及修复它的方法或如何配置 @ 987654327@ 以便它妥善处理此问题。我尝试查看文档,但也许我错过了一些东西。我没有找到我要找的东西。

有什么想法吗?

【问题讨论】:

  • config.php中$config['base_url']的值是多少?

标签: php .htaccess codeigniter login base-url


【解决方案1】:

您可以尝试将base_url 设置为/index.php/ 吗?所以它前面也有正斜杠?

如果失败,请尝试:http://localhost/CIintranet/index.php/

通常是简单的事情!

【讨论】:

  • 第一个试过了,还是不行。尝试了第二个,瞧。我不确定它为什么会起作用,但我知道它做了什么。奇迹般有效。谢谢!
【解决方案2】:

如果你使用...?

<?php echo form_open('welcome/login_submit') ?>
...
<?php echo form_close(); ?>

激活助手:form

【讨论】:

  • 不是我不会尝试,而是 codeigniter 表单真的是解决这个问题的唯一方法吗?我可以发誓一定有一种方法可以通过弄乱 base_url 或其他东西来解决它。我真的不知道。如果这是最好的解决方案,那么这就是我将采用的方法。
猜你喜欢
  • 1970-01-01
  • 2017-11-08
  • 2011-09-03
  • 2019-02-03
  • 2015-12-24
  • 1970-01-01
  • 2021-08-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多