在Codeigniter 3中提交表单后,localhost将重定向到127.0.0.1

时间:2016-02-23 06:26:27

标签: codeigniter

我的代码中存在问题。我的代码中有一个表单如下:

<?php echo form_open('users/auth/login', array('class' => 'form floating-label')); ?>   
    <div class="form-group">
        <input type="text" class="form-control" id="username" name="username" />
        <label for="username">Username</label>
    </div>
    <div class="form-group">
        <input type="password" class="form-control" id="password" name="password" />
        <label for="password">Password</label>
        <p class="help-block"><a href="#">Forgotten?</a></p>
    </div>
    <br/>
    <div class="row">
        <div class="col-xs-12 text-right">
            <?php echo $this->session->flashdata('note'); ?>
            <button class="btn btn-primary btn-raised btn-ink" type="submit">Login Account</button>
        </div>
    </div>
<?php echo form_close(); ?>

然后点击提交后,我将localhost重定向到127.0.0.1

提交表单后,我将其重定向到

http://127.0.0.1/teradasys/index.php/user/login

这是我的控制器

public function index() {

       if($this->aauth->is_loggedin()) {

       } else {
            $data['page_header'] = 'Login Form';
            $this->load->view('users/login', $data);
       }

    }

    public function login() {

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

        if ($this->aauth->login($identifier, $password, true)){
            return true;
        } else {
            $note = $this->aauth->get_errors_array();
            $this->session->set_flashdata('note', $note[0]);

            $data['page_header'] = 'Login Form';
            $this->load->view('users/login', $data);

        }

    }

2 个答案:

答案 0 :(得分:5)

请在application / config / config.php

中查看您的基本网址

并改变它。

$config['base_url'] = 'http://localhost/test/';

答案 1 :(得分:3)

请在application / config / config.php

中查看您的基本网址

改变
$config['base_url'] = 'http://localhost/test/';

$config['base_url'] = (isset($_SERVER['HTTPS']) ? "https://" : "http://") . $_SERVER['HTTP_HOST'] . preg_replace('@/+$@', '', dirname($_SERVER['SCRIPT_NAME'])) . '/';

$config['base_path'] = $_SERVER['DOCUMENT_ROOT'] . preg_replace('@/+$@', '', dirname($_SERVER['SCRIPT_NAME'])) . '/';

放置此内容后无需更改任何内容。如果您使用本地或现场主持人。