IP 地址显示在 CodeIgniter 的表单操作中 http://::1/codeigniter/ 在 html 源代码中

IP address is showing in form action with CodeIgniter http://::1/codeigniter/ in html sourcecode

我在 Xampp 上安装了 CI 脚本。目前我正在处理表格,当我点击 html 上的提交时,它什么也没做。

我试过了

echo form_open('verifylogin');
echo form_open();

它在源代码上显示为

<form action="http://::1/codeigniter/verifylogin">
<form action="http://::1/codeigniter/">

分别。

我不明白这个 "http://::1/" 是什么以及如何摆脱它?

如果ip地址显示在form actionurl

  • http://::1/yourproject/
  • http://127.0.0.1/yourproject/

很可能您将基础 url 留空

/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
|   http://example.com/
|
| WARNING: You MUST set this value!
|
| If it is not set, then CodeIgniter will try guess the protocol and path
| your installation, but due to security concerns the hostname will be set
| to $_SERVER['SERVER_ADDR'] if available, or localhost otherwise.
| The auto-detection mechanism exists only for convenience during
| development and MUST NOT be used in production!
|
| If you need to allow multiple domains, remember that this file is still
| a PHP script and you can easily do that on your own.
|
*/

$config['base_url'] = '';

现在最新版本的 codeIgniter 不建议您将 base_url 留空。

  • $config['base_url'] = 'http://localhost/yourproject/';
  • $config['base_url'] = 'http://www.example.com/';

/

结束 url 总是好的

您可能需要在此处为​​您的表单创建路由

application > config > routes.php

CodeIgniter 3: Routing

CodeIgniter 2: Routing


更新:

With CodeIgniter 3 + versions:

创建文件时请记住,在 file namesclasses 上,首字母仅 大写。

有时会发生的情况是,它可能在小写的本地主机环境中运行良好,但当您转到实时服务器时 有时 会抛出错误或不提交表单正确等等

示例:来自 Controllers This also applies to Models

这是有效的

文件名: Verifylogin.php

<?php

class Verifylogin extends CI_Controller {

    public function __construct() {
       parent::__construct();
    }

    public function index() {

    }

}

这是有效的

文件名: Verify_login.php

<?php

class Verify_login extends CI_Controller {

    public function __construct() {
       parent::__construct();
    }

    public function index() {

    }

}

无效有效

文件名: verifylogin.php

class verifylogin extends CI_Controller {

    public function __construct() {
       parent::__construct();
    }

    public function index() {

    }

}

无效有效

文件名: Verify_Login.php

class Verify_Login extends CI_Controller {

    public function __construct() {
       parent::__construct();
    }

    public function index() {

    }

}

Codeigniter Doc's

转到 application/config/config。php 设置 base_url

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

并刷新您的应用程序

然后 ::1 错误应该消失了。

转到System/core/Config。php

在第 84 行设置配置

public function __construct()
    {
        $this->config =& get_config();

    // Set the base_url automatically if none was provided
    if (empty($this->config['base_url']))
    {
        // The regular expression is only a basic validation for a valid "Host" header.
        // It's not exhaustive, only checks for valid characters.
        if (isset($_SERVER['HTTP_HOST']) && preg_match('/^((\[[0-9a-f:]+\])|(\d{1,3}(\.\d{1,3}){3})|[a-z0-9\-\.]+)(:\d+)?$/i', $_SERVER['HTTP_HOST']))
        {
            $base_url = (is_https() ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST']
                .substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
        }
        else
        {
            $base_url = 'http://localhost/';
        }

        $this->set_item('base_url', $base_url);
    }


    log_message('info', 'Config Class Initialized');
}

从 url

中删除 /

上一个:

<li><a href="/<?=site_url('contacts/create')?>">New Contact</a></li>

之后:

<li><a href="<?=site_url('contacts/create')?>">New Contact</a></li>

我通过删除重定向中的“/”解决了这个问题

之前:

header("Location: /index.php?error=TRUE")

之后:

header("Location: index.php?error=TRUE")